Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#易趣API详细级别_C#_Xml_Soap_Ebay Api - Fatal编程技术网

C#易趣API详细级别

C#易趣API详细级别,c#,xml,soap,ebay-api,C#,Xml,Soap,Ebay Api,我正在开发一个C#应用程序,可以返回所有可用的易趣类别。不幸的是,我无法解决有关详细级别的问题 DetailLevel是请求的一部分,它告诉eBay服务器响应的外观 我必须将DetailLevel设置为“ReturnAll”。通过遵循在线提供的代码示例,我还没有成功 以下是我目前使用的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Thre

我正在开发一个C#应用程序,可以返回所有可用的易趣类别。不幸的是,我无法解决有关详细级别的问题

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”,我得到了“Success”的值,到目前为止这是一个很好的值,但是CategoryCount总是显示为“0”。我有一个SOAP测试工具,如果“DetailLevel”设置不正确,它会给我相同的结果。你能帮我解决这个问题吗?

DetailLevel实际上是DetailLevelCodeType(C++)的数组(或相应的C#DetailLevelCodeTypeCollection()) 因此,将代码更改为:

        var detailLevel = new DetailLevelCodeTypeCollection();
        detailLevel.Add(DetailLevelCodeType.ReturnAll);
应该有用。保存请求/响应也很好 在发送请求之前/接收响应之后,检查xml文件的语法。
尊敬。

您可以尝试使用eBayAPIInterfaceService(添加web引用)而不是eBayAPIInterfaceClient。

易趣网参考:但你应该检查版本。有时最新版本有问题。因此,尝试其他版本。经验:

设置详细级别:

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