eBay 查找 API .NET SDK“findItemsAdvanced”返回空响应

发布于 2024-09-16 13:50:25 字数 3694 浏览 7 评论 0原文

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

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

FindItemsAdvancedResponse response = service.findItemsAdvanced(request);

名为“response”的对象返回为 null。

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

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

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

Progam.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;

            }

        }
    }
}

I'm trying to use the eBay Finding API to send an advanced search request and return the results. I have included my code below.

For some reason when I get to the following line:

FindItemsAdvancedResponse response = service.findItemsAdvanced(request);

the object called "response" is coming back as null.

I'm not sure where I'm going wrong and no exception is being thrown from the call to service.findItemsAdvanced()

If you could take a look and offer any advice at all I would be most grateful.

Here is my program.cs up until the problem

Progam.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);

and here is the code for the class called "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;

            }

        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱她像谁 2024-09-23 13:50:25

当我从通过关键字查找转向使用高级方法时,我遇到了完全相同的问题。我自己花了一段时间摸不着头脑,但结果发现有一个简单的修复方法:

您的标题 X-EBAY-SOA-OPERATION-NAME 读取为 findItemsByKeywords。将其更改为 findItemsAdvanced 应该可以解决问题。

I had exactly the same problem when I went from finding by keywords to using the advanced method. I spent a while scratching my head myself but it turned out to have a simple fix:

Your header X-EBAY-SOA-OPERATION-NAME reads findItemsByKeywords. Changing it to findItemsAdvanced should do the trick.

七度光 2024-09-23 13:50:25

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

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

If you leave any of the filters blank in the filter array you will get the SOA Operation Header missing exception whether or not you have included the headers correctly.

You should check the filters are not null before applying them to your request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文