Skip to main content
Published: December 08 2009, 5:23:00 AMUpdated: November 28 2020, 8:05:50 PM

How to call FindingService - findItemsByKeywords API from .NET framework using SOAP request 

  1. Add a web reference to the Finding API definition file
     
    http://developer.ebay.com/webservices/Finding/latest/FindingService.wsdl
  2. Create a class that derives from FindingService class. For example, “CustomFindingService.cs”. Override the GetWebRequest method and set the HTTP request headers such as globalID, protocol, appName, operationName, serviceName and version.    
  3. Create an object for the required request type. For example,
       FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();  
  4. Provide value for the required properties.
        request. keywords = “canon”; // for example 
  5. Create an object to the required response type. For example,
       FindItemsByKeywordsResponse response = service.findItemsByKeywords(request);  
  6. Explore the response object for response data.    

The following is the code sample for findItemsByKeywords API call using C#.NET

 

Code in the Program.cs file

using System;

using System.Collections.Generic;

using System.Text;

using FindingAPI_Sample.com.ebay.developer;

 

namespace FindingAPI_Sample

{

    class Program

    {

        static void Main (string[] args)

        {

            try

            {

                // Creating an object to the BestMatchService class

                CustomFindingService service = new CustomFindingService();

                service.Url = "http://svcs.ebay.com/services/search/FindingService/v1";

 

                // Creating request object for FindBestMatchItemDetailsByKeywords API

                FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();

                // Setting the required property values

                request.keywords = "canon";

 

                // Setting the pagination

                PaginationInput pagination = new PaginationInput();

                pagination.entriesPerPageSpecified = true;

                pagination.entriesPerPage = 25;

                pagination.pageNumberSpecified = true;

                pagination.pageNumber = 1;

                request.paginationInput = pagination;

 

                // Creating response object

                FindItemsByKeywordsResponse response = service.findItemsByKeywords(request);

                SearchResult result = response.searchResult;

                Console.WriteLine("Find items results");

 

                // Looping through response object for result

                foreach (SearchItem item in result.item)

                {

                    Console.WriteLine("Item ID: " + item.itemId);

                    Console.WriteLine("Item Title: " + item.title);

                    Console.WriteLine("-------------------------------------------");

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine("* Error: " + ex.Message);

            }

            Console.WriteLine("Press ENTER key to exit...");

            Console.ReadLine();

        }

    }

}

 

Code in the CustomFindingService.cs file

using System;

using System.Collections.Generic;

using System.Text;

using FindingAPI_Sample.com.ebay.developer;

using System.Net;

 

namespace FindingAPI_Sample

{

    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", "YOUR_APP_ID_HERE");

                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;

            }

        }

    }

}

 

Note:

Please see the attachment for a sample web application to make findItemsByKeywords API call.

 

 

Attachment Details:

The web application is created with using Microsoft Visual Studio 2005. Please read the README.txt before running the sample.

How well did this answer your question?
Answers others found helpful