3

我正在尝试使用 eBay Finding API 发送高级搜索请求并返回结果。我在下面包含了我的代码。

出于某种原因,当我到达以下行时:

FindItemsAdvancedResponse response = service.findItemsAdvanced(request);

名为“响应”的对象将返回为空。

我不确定我哪里出错了,并且没有从调用中抛出异常service.findItemsAdvanced()

如果您能看一下并提供任何建议,我将不胜感激。

这是我的program.cs,直到出现问题

程序.cs

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using EbayParser.com.ebay.developer;
using System.Net;
namespace EbayParser
{

    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                // Creating an object to the BestMatchService class

                CustomFindingService service = new CustomFindingService();
                service.Url = "http://svcs.sandbox.ebay.com/services/search/FindingService/v1";

                com.ebay.developer.FindItemsAdvancedRequest request = new EbayParser.com.ebay.developer.FindItemsAdvancedRequest();

                //Create Filter Objects
                com.ebay.developer.ItemFilter filterEndTimeFrom = new EbayParser.com.ebay.developer.ItemFilter();
                com.ebay.developer.ItemFilter filterEndTimeTo = new EbayParser.com.ebay.developer.ItemFilter();
                com.ebay.developer.ItemFilter filterCatID = new EbayParser.com.ebay.developer.ItemFilter();

                //Set Values for each filter
                filterEndTimeFrom.name = EbayParser.com.ebay.developer.ItemFilterType.EndTimeFrom;
                filterEndTimeFrom.value = new string[] { "" };

                filterEndTimeTo.name = EbayParser.com.ebay.developer.ItemFilterType.EndTimeTo;
                filterEndTimeTo.value = new string[] { "" };

                filterCatID.name = EbayParser.com.ebay.developer.ItemFilterType.EndTimeFrom;
                filterCatID.value = new string[] { "" };

                //Create the filter array
                com.ebay.developer.ItemFilter[] itemFilters = new EbayParser.com.ebay.developer.ItemFilter[3];

                //Add Filters to the array
                itemFilters[0] = filterCatID;
                itemFilters[1] = filterEndTimeFrom;
                itemFilters[2] = filterEndTimeTo;

                request.itemFilter = itemFilters;
                request.keywords = "ipod";

                // Creating response object

                FindItemsAdvancedResponse response = service.findItemsAdvanced(request);

这是名为“CustomFindingService.cs”的类的代码

CustomFindingService.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using EbayParser.com.ebay.developer;

namespace EbayParser
{
    class CustomFindingService : FindingService
    {
        protected override System.Net.WebRequest GetWebRequest(Uri uri)
        {

            try
            {

                HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);

                request.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

                request.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");

                request.Headers.Add("X-EBAY-SOA-SERVICE-NAME", "FindingService");

                request.Headers.Add("X-EBAY-SOA-MESSAGE-PROTOCOL", "SOAP11");

                request.Headers.Add("X-EBAY-SOA-SERVICE-VERSION", "1.0.0");

                request.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");

                return request;

            }

            catch (Exception ex)
            {

                throw ex;

            }

        }
    }
}
4

2 回答 2

2

当我从按关键字查找到使用高级方法时,我遇到了完全相同的问题。我花了一段时间自己挠头,但结果证明有一个简单的解决方法:

您的标题X-EBAY-SOA-OPERATION-NAMEfindItemsByKeywords. 将其更改为findItemsAdvanced应该可以解决问题。

于 2011-02-23T14:54:14.143 回答
1

如果您将过滤器数组中的任何过滤器留空,无论您是否正确包含了标题,您都会收到 SOA 操作标题丢失异常。

在将过滤器应用于您的请求之前,您应该检查过滤器是否为空。

于 2010-09-03T12:59:00.790 回答