Skip to main content
Published: December 04 2009, 5:57:00 AMUpdated: November 28 2020, 8:05:38 PM

How to call BestMatch API from .NET framework using SOAP request 

Please follow the steps below to call BestMatchAPI from .NET framework.     

  1. Add a web reference to the BestMatch API definition file
    http://developer.ebay.com/webservices/best-match-item-details/latest/BestMatchItemDetailsService.wsdl         
  2. Create a class that derives from BestMatchItemDetailsService class. For example, BestMatchService.cs   Override the GetWebRequest method and set the HTTP request headers such as globalID, protocol, token, operationName, serviceName and version.  
  3. Create an object for the required request type. For example,
       FindBestMatchItemDetailsByKeywordsRequest request = new FindBestMatchItemDetailsByKeywordsRequest ();  
  4. Provide value for the required properties.
        request. keywords = “canon”;  
  5. Create an object to the required response type. For example,
       FindBestMatchItemDetailsByKeywordsResponse response = service. findBestMatchItemDetailsByKeywords (request);  
  6. Explore the response object for response data.    

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

 

 

Code in the Program.cs file

using System;

using System.Collections.Generic;

using System.Text;

using BestMatchSample_SOAP.com.ebay.developer;

 

namespace BestMatchSample_SOAP

{

    class Program

    {

        static void( Main (string[] args)

        {           

            try

            {

                // Creating an object to the BestMatchService class

                BestMatchService service = new BestMatchService();

                service.Url = "https://svcs.ebay.com/services/search/BestMatchItemDetailsService/v1";

                // Creating request object for FindBestMatchItemDetailsByKeywords API

                FindBestMatchItemDetailsByKeywordsRequest request = new FindBestMatchItemDetailsByKeywordsRequest();

                // Setting the required property values

                request.keywords = "canon";

                request.siteResultsPerPage = 25;

                request.entriesPerPageSpecified = true;

                request.entriesPerPage = 10;

 

                // Creating response object

                FindBestMatchItemDetailsByKeywordsResponse response = service.findBestMatchItemDetailsByKeywords(request);

                BestMatchSearchResult result = response.searchResult;

                Console.WriteLine("Best Match Results");

 

                // Looping through response object for result

                foreach (SearchItemGroup itemGroup in result.searchItemGroup)

                {

                    foreach (BestMatchSearchItem item in itemGroup.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 BestMatchService.cs file

using System;

using System.Collections.Generic;

using System.Text;

using BestMatchSample_SOAP.com.ebay.developer;

using System.Net;

 

namespace BestMatchSample_SOAP

{

    class BestMatchService : BestMatchItemDetailsService

    {

        protected override WebRequest GetWebRequest(Uri uri)

        {

            try

            {

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

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

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

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

                request.Headers.Add("X-EBAY-SOA-SECURITY-TOKEN", "YOUR_TOKEN_HERE");

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

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

                return request;

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

    }

}

 

 

 

 

How well did this answer your question?