For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

Merchandising API - .SOAP sample using C# .NET

  • Answer ID 1507
  • Published 11/19/2009 09:03 PM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1507

Steps to make a SOAP request using C#:

  1. Set a web reference to the WSDL:
    http://developer.ebay.com/webservices/merchandising/latest/MerchandisingService.wsdl
  2. In the sample the reference is named MerchandisingAPI
  3. Create a custom class that derives from MerchandisingService class
    In the sample the File is named customMerchandisingService.cs

  4. Override the GetWebRequest method and set the HTTP request headers
    (You need to specify the AppID, Operation, Service, Protocol and Version in the HTTP headers)
  5. In the main program, use the custom class to  make the call.

Here is a Console application sample code in C# for getMostWatchedItems:

Code in the Program.cs file

using System;
using System.Collections.Generic;
using System.Text;
using MerchandisingSample.MerchandisingAPI;

namespace MerchandisingSample
{
    class Program
    {
        static void Main(string[] args)
        {
                //Use the custom class
        customMerchandisingService svc = new customMerchandisingService(); 
                //Set the production URL
                svc.Url = "https://svcs.ebay.com/MerchandisingService"
        GetMostWatchedItemRequest request = new GetMostWatchedItemRequest(); 
        request.categoryId =  "617";
        MerchandisingServiceItemResponse response = svc.getMostWatchedItems(request); 
                
               foreach (Item item in response.itemRecommendations)
               {
                   //process results
                   string title = item.title;
                   string itemID = item.itemId;

               }

       
}
    }
}

Code in customMerchandisingService.cs file

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using MerchandisingSample.MerchandisingAPI;

namespace MerchandisingSample
{
   
class customMerchandisingService : MerchandisingAPI.MerchandisingService
   
{
       
protected override System.Net.WebRequest GetWebRequest(Uri uri)
       
{
           
HttpWebRequest req = (HttpWebRequest)base.GetWebRequest(uri);
           
//Set the AppID, Operation, Service, Protocol and Version as HTTP Headers
           
req.Headers.Add("EBAY-SOA-CONSUMER-ID", "Your AppID");
           
req.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "getMostWatchedItems");
           
req.Headers.Add("X-EBAY-SOA-SERVICE-NAME", "MerchandisingService");
           
req.Headers.Add("X-EBAY-SOA-MESSAGE-PROTOCOL", "SOAP11");
           
req.Headers.Add("X-EBAY-SOA-SERVICE-VERSION", "1.1.0");
           
return req;
       
}
   
}
}

 

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter