3

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;

            }

        }
    }
}
Cray
  • 2,774
  • 7
  • 22
  • 32
Dan Harris
  • 1,336
  • 1
  • 21
  • 44
  • I've blanked out my App-ID in the above code. – Dan Harris Sep 01 '10 at 19:51
  • Have you used Fiddler to look at the request and response? – Alan Sep 01 '10 at 19:56
  • I haven't tried that yet but will. If I change the "service" object to EbayFindingService instead of the custom class than inherits EbayFindingService I get an error that says "SOA header missing" What is the correct way to set the header for a FindItemsAdvancedRequest item? – Dan Harris Sep 01 '10 at 20:06
  • Even if I don't end up with the exact answer, if somebody could even point me to, or write a simple example of using the Ebay SDK that would be great. Any examples i've found so far just end up throwing errors, or are out dated and no longer work. – Dan Harris Sep 01 '10 at 20:31

2 Answers2

2

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.

janisz
  • 6,292
  • 4
  • 37
  • 70
Auc
  • 158
  • 1
  • 2
  • 10
1

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.

Dan Harris
  • 1,336
  • 1
  • 21
  • 44