For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

C#.NET code sample to call eBay Trading API using .NET framework 4

  • Answer ID 2045
  • Published 04/24/2012 05:30 AM
  • Updated 10/20/2013 06:42 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=2045
Product

How to consume and use eBay Trading Service using .NET framework 4


  1. Add a web service reference to the ebaySvc.wsdl
    (Please use the latest version of the WSDL)
        http://developer.ebay.com/webservices/latest/ebaySvc.wsdl
  2. Create an object for the eBayAPIInterfaceClient class. For example,
    eBayAPIInterfaceClient service = new eBayAPIInterfaceClient
    ("eBayAPI", endpointURL);
    where “eBayAPI” is the endpointConfigurationName and endpointURL is the signin URL.
  3. Create an object for CustomSecurityHeaderType and set the token. For example,
        CustomSecurityHeaderType cred = new CustomSecurityHeaderType();  
  4. Create an object to the required response type. For example,
        GeteBayOfficialTimeResponseType res = service.GeteBayOfficialTime(ref cred, request);  
  5. Explore the response object for response data.
  6. Increase the maxBufferSize and maxReceivedMessageSize of the <binding> element in the App.Config file to 655360
  7. Similarly increase the maxNameTableCharCount and maxArrayLength of the <readerQuotas> element to 163840.


The following is the code sample for findItemsByKeywords API call using C#.NET framework 4.

 

Code in the Program.cs file

using System;

using System.Configuration;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel.Channels;

using System.ServiceModel;

using eBayTrading_WSDL_Sample.eBayAPIInterfaceService;

 

namespace eBayTrading_WSDL_Sample

{

    class Program

    {

        static void Main(string[] args)

        {

            string signinURL = "https://api.sandbox.ebay.com/wsapi";

            string callname = "GeteBayOfficialTime";

            string siteID = "0";

            string appID = "YOUR_APPID_HERE";

            string version = "768";

            string eBayToken = "YOUR_TOKEN _HERE”;

            string endpointURL = signinURL + "?callname=" + callname +

                                "&siteid=" + siteID +

                                "&appid=" + appID +

                                "&version=" + version +

                                "&routing=default";

 

            eBayAPIInterfaceClient service = new eBayAPIInterfaceClient("eBayAPI", endpointURL);

 

            EndpointAddress address = new EndpointAddress(endpointURL);

            service.Endpoint.Address = address;

            GeteBayOfficialTimeRequestType request = new GeteBayOfficialTimeRequestType();     

            request.Version = version;

            request.WarningLevelSpecified = true;

            request.WarningLevel = WarningLevelCodeType.High;

            CustomSecurityHeaderType cred = new CustomSecurityHeaderType();

            cred.eBayAuthToken = eBayToken;

            GeteBayOfficialTimeResponseType res = service.GeteBayOfficialTime(ref cred, request);

            Console.WriteLine("Ack: " + res.Ack.ToString());

            Console.WriteLine("Official Time is: " + res.Timestamp);

            Console.ReadLine();

 

        }

    }

}

 

 

App.Config file entries

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

   

    <system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="eBayAPISoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00"

                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"

                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="655360" maxBufferPoolSize="524288" maxReceivedMessageSize="655360"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

                    useDefaultWebProxy="true">

                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="163840"

                        maxBytesPerRead="4096" maxNameTableCharCount="163840" />

                    <security mode="Transport">

                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />

                        <message clientCredentialType="UserName" algorithmSuite="Default" />

                    </security>

                </binding>

                <binding name="eBayAPISoapBinding1" closeTimeout="00:01:00" openTimeout="00:01:00"

                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"

                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="655360" maxBufferPoolSize="524288" maxReceivedMessageSize="655360"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

                    useDefaultWebProxy="true">

                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="163840"

                        maxBytesPerRead="4096" maxNameTableCharCount="163840" />

                    <security mode="None">

                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />

                        <message clientCredentialType="UserName" algorithmSuite="Default" />

                    </security>

                </binding>

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="https://api.ebay.com/wsapi" binding="basicHttpBinding"

                bindingConfiguration="eBayAPISoapBinding" contract="eBayAPIInterfaceService.eBayAPIInterface"

                name="eBayAPI" />

        </client>

    </system.serviceModel>

</configuration>

 

 

 

 

Note:

Please see the attachment for a sample console application to make GeteBayOfficialTime call.

File Attachments

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter