Home
Find the answer to your question
How to call BestMatch API from .NET framework using SOAP request
Please follow the steps below to call BestMatchAPI from .NET framework.
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; } } } }
|