繁体   English   中英

C#eBay API DetailLevel

[英]C# eBay API DetailLevel

我正在开发一个C#应用程序,该应用程序应返回所有可用的eBay类别。 不幸的是,我无法解决有关DetailLevel的问题。

DetailLevel是请求的一部分,它告诉eBay服务器响应的外观。

我必须将DetailLevel设置为“ ReturnAll”。 通过遵循在线提供的代码示例,我还没有成功。

这是我到目前为止使用的代码:

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);
            }
        }
    }
}

控制台会向我显示“ Ack”值和“ CategoryCount”,这是eBay返回的类别数。

对于“ Ack”,我得到的值“ Success”到目前为止是不错的,但是CategoryCount始终显示“ 0”。 我有一个SOAP测试工具,如果未正确设置“ DetailLevel”,它会给我相同的结果。 您能帮我解决这个问题吗?

DetailLevel实际上是Array_Of_DetailLevelCodeType(C ++),(或对应于c#DetailLevelCodeTypeCollection()),因此将代码更改为:

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

应该管用。 将请求/响应保存到xml文件之前,在发送请求之前/在接收响应之后保存请求/响应也是很好的。 问候。

您可以尝试使用eBayAPIInterfaceService(添加Web参考)代替eBayAPIInterfaceClient。

eBay Web参考: http : //developer.ebay.com/webservices/latest/ebaySvc.wsdl,但是您应该检查版本。 有时最新版本有问题。 因此,请尝试其他版本。 实验: http//developer.ebay.com/webservices/1025/ebaySvc.wsdl

设置详细程度:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM