Skip to main content
Published: November 19 2009, 10:03:00 PMUpdated: November 28 2020, 8:04:08 PM

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