Contents

This document contains the following sections contain the following information for making calls:

Making an SDK Call

Note: Many APIs are available from eBay. However, the eBay .NET SDK supports only the Trading API.

In order to make an SDK call to the Trading Service at an eBay site, your application must first instantiate ApiContext, which is a singleton: all SDK calls to eBay during your application session use the same Apicontext instance. Your application must set three properties on that ApiContext object:

After ApiContext is created and its properties set, you instantiate the SDK call wrapper you want to use, for example, AddItemCall if you want to list (AddItem) an item on eBay. Supply any needed input data, send the request, and handle the response:

Required Libs and Classes

Each .NET SDK program must add a reference to the library eBay.Service.dll, located at the SDK home directory: this library must be redistributed with your program.

In order to use the SDK classes, you need to import these classes:

Communication Prototype

The following code samples in C# and VB.NET show the bare minimum of code needed to send a call to eBay.

Communicating with eBay using C#

The following code is adapted from the Hello World sample located in the SDK subdirectory /Samples/C#/HelloWorld. There are some minor changes from that sample; for example, the sample stores the token and the endpoint in the App.config file but we hardcode the values directly here for the sake of clarity. This code gets the current eBay time at the US site and displays it in a console window.

//Instantiate and set properties in ApiContext
ApiContext apiContext = GetApiContext();

//Instantiate the call wrapper class
GeteBayOfficialTimeCall apiCall = new GeteBayOfficialTimeCall(apiContext);

//Send the call to eBay and get the results
DateTime officialTime = apiCall.GeteBayOfficialTime();

 //Handle the result returned
 Console.WriteLine("eBay official Time: " + officialTime);

 // Instantiating and setting ApiContext
static ApiContext GetApiContext()
{
    //apiContext is a singleton,
    if (apiContext != null)
    {
        return apiContext;
    }

    else
    {
        apiContext = new ApiContext();

        //supply Api Server Url
        apiContext.SoapApiServerUrl ="https://api.sandbox.ebay.com/wsapi";

        //Supply user token
        ApiCredential apiCredential = new ApiCredential();

        //Just a partial token is shown for display purposes
        apiCredential.eBayToken ="BgBBBB**BQBBBB**BBBBBB**XrJITB**nY+sHZ2PrBmdj6wVnY+sEZ2PrB2dj6wFk4HoBJSDpQ6dj6x9nY+seQ**+FkBBB**BBMBBB**...";
        apiContext.ApiCredential = apiCredential;

        //Specify site: here we use US site
        apiContext.Site = SiteCodeType.US;

        return apiContext;
    } // else

} //GetApiContext

In the sample code, notice that ApiContext is instantiated and its properties set only if it has not yet been instantiated. Notice also that the user (authorization) token is hardcoded here, which would be appropriate only for single-user applications. For a discussion on authorization tokens and how to handle tokens in multi-user applications see Handling Authorization in Your Application.

Communicating with eBay using VB.NET

The following code is also adapted from the Hello World sample with a few changes. As in the previous snippet, we hardcode the values directly for the sake of clarity. This code gets the current eBay time at the US site and displays it in a console window.

//Instantiate and set properties in ApiContext
Private apiContext As ApiContext = Nothing

Sub Main()
    'Initialize ApiContext and set its properties
    Dim apiContext As ApiContext = GetApiContext()

    'Instantiate the call wrapper class
    Dim apiCall As GeteBayOfficialTimeCall = New GeteBayOfficialTimeCall(apiContext)

    'Send the call to eBay and get the results
    Dim officialTime As DateTime = apiCall.GeteBayOfficialTime()

    'Handle the result returned
    Console.WriteLine("eBay official Time: " + officialTime)
End Sub

'Instantiating and setting ApiContext
Private Function GetApiContext() As ApiContext

    'apiContext is a singleton
    If (apiContext IsNot Nothing) Then
        Return apiContext
    Else

        apiContext = New ApiContext

        'supply Api Server Url
        apiContext.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi"

        'Supply user token
        Dim apiCredential As ApiCredential = New ApiCredential

        'Just a partial token is shown for display purposes
        apiCredential.eBayToken = "BgBBBB**BQBBBB**BBBBBB**XrJITB**nY+sHZ2PrBmdj6wVnY+sEZ2PrB2dj6wFk4HoBJSDpQ6dj6x9nY+seQ**+FkBBB**BBMBBB**..."
        apiContext.ApiCredential = apiCredential

        'set eBay Site target to US
        apiContext.Site = SiteCodeType.US

        Return apiContext
    End If

End Function

In the sample code, notice that ApiContext is instantiated and its properties set only if it has not yet been instantiated. Notice also that the user (authorization) token is hardcoded here, which would be appropriate only for single-user applications. For a discussion on authorization tokens and how to handle tokens in multi-user applications see Handling Authorization in Your Application.

Trading Service URL/Endpoints (SOAP)

All SDK requests must be sent to either the eBay Sandbox or Production API Gateway. This authenticated service uses secure endpoints. Notice that these are the SOAP endpoints because the Trading Service uses SOAP.

Sandbox Gateway URL (endpoint):

https://api.sandbox.ebay.com/wsapi

Production Gateway URL (endpoint):

https://api.ebay.com/wsapi

HTTP Headers and URL Parameters

The .NET SDK automatically supplies any required HTTP headers and URL parameters.

Schema Location

The SDK kernel is prebuilt to use the WSDL version indicated in the SDK release. However, in rare cases, advanced eBay developers may wish to update the SDK kernel to the latest WSDL.

If you must update the SDK kernel to a more recent WSDL, you can download WSDLs from https://developer.ebay.com/webservices/Version/ebaySvc.wsdl, where Version is replaced by the version number of the WSDL release to be downloaded, for example, https://developer.ebay.com/webservices/687/ebaySvc.wsdl.

The latest released WSDL version can always be found at https://developer.ebay.com/webservices/latest/ebaySvc.wsdl.

Testing

You use the sandbox environment to test your application. The sandbox supports all Trading API calls unless stated otherwise in the Trading API documentation. For more information about the Sandbox testing environment, see Testing Applications.





© 2008–2010 eBay Inc. All rights reserved.
eBay and the eBay logo are registered trademarks of eBay Inc.
All other brands are the property of their respective owners.