skip to Main Content

I am developing a C# application which should return all eBay categories available. Unfortunately I am not able to solve an issue about the DetailLevel.

The DetailLevel is part of the request and tells the eBay servers how the response should look.

I have to set the DetailLevel to “ReturnAll”. By following the code samples that are available online I had not success yet.

Here is the code I am using so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EbayGetCategories.ebayAPI;
using System.IO;
using System.ServiceModel;
using System.Xml;
using System.Data.OleDb;

namespace EbayGetCategories
{
    class Program
    {
        static void Main(string[] args)
        {
            int anzahl;
            string endpoint = "https://api.ebay.com/wsapi";
            string callName = "GetCategories";
            string siteId = "0";
            string appId = "YOUR_APPID";     // use your app ID
            string eBayToken = "YOUR_TOKEN";
            string version = "793";
            // Build the request URL
            string requestURL = endpoint
            + "?callname=" + callName
            + "&siteid=" + siteId
            + "&appid=" + appId
            + "&version=" + version
            + "&routing=default";
            // Create the service
            eBayAPIInterfaceClient service = new eBayAPIInterfaceClient("eBayAPI", requestURL);
            // Assign the request URL to the service locator.
            EndpointAddress address = new EndpointAddress(requestURL);
            service.Endpoint.Address = address;
            // Set credentials
            // Make the call to GeteBayOfficialTime
            var detailLevel = new DetailLevelCodeType[1];
            detailLevel[0] = DetailLevelCodeType.ReturnAll;
            GetCategoriesRequestType request = new GetCategoriesRequestType();
            request.WarningLevelSpecified = true;
            request.WarningLevel = WarningLevelCodeType.High;
            request.Version = version;
            request.DetailLevel = detailLevel;
            CustomSecurityHeaderType cred = new CustomSecurityHeaderType();
            cred.eBayAuthToken = eBayToken;
            GetCategoriesResponseType response = service.GetCategories(ref cred, request);
            Console.WriteLine(response.Ack);
            Console.WriteLine(response.CategoryCount);
            Console.ReadKey();
            OleDbConnection con = new OleDbConnection();
            OleDbCommand cmd = new OleDbCommand();
            con.ConnectionString = @"Provider=PervasiveOLEDB;" + @"Data Source=EBAYAPIWARNER;" + @"Location=192.168.0.11;";
            cmd.Connection = con;
            cmd.CommandText = "INSERT INTO 'ebay_categories' VALUES (2,2,'cat',2,'test')";
            try
            {
                con.Open();
                anzahl = cmd.ExecuteNonQuery();
                Console.WriteLine(anzahl);
                con.Close();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

The Console shows me the “Ack” values and the “CategoryCount”, which is the number of categories returned by eBay.

For “Ack” I get the value “Success” which is good so far, but CategoryCount always shows me “0”. I have a SOAP Test Tool which gives me the same result if the “DetailLevel” is not set correctly. Could you please help me to solve this issue?

2

Answers


  1. DetailLevel is actually Array_Of_DetailLevelCodeType (C++), (Or coresponding c# DetailLevelCodeTypeCollection() )
    So changing Your code to:

            var detailLevel = new DetailLevelCodeTypeCollection();
            detailLevel.Add(DetailLevelCodeType.ReturnAll);
    

    Should work. It’s also good to save request/Response
    Before send Request / After receive Response to xml file, to check out it’s syntax.
    Regards.

    Login or Signup to reply.
  2. You can try to use eBayAPIInterfaceService (add web reference) instead of eBayAPIInterfaceClient.

    ebay web ref: http://developer.ebay.com/webservices/latest/ebaySvc.wsdl but you should check the version. Sometimes latest version has a problem. So try to other versions. exp: http://developer.ebay.com/webservices/1025/ebaySvc.wsdl

    Set detaillevel:

    request.DetailLevel = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search