Skip to main content
Published: February 28 2012, 5:15:00 AMUpdated: November 28 2020, 10:19:01 PM

How to consume and use ProductService using .NET framework

  1. Add a web reference to the ProductService WSDL
        http://developer.ebay.com/webservices/product/latest/ProductService.wsdl
  2. Create a class that derives from ProductService class. For example, “CustomProductService.cs”.
    Override the GetWebRequest method and set the HTTP request headers such as protocol, operationName, serviceName, securityAppName.
  3. Create an object for the required request type. For example,
       
    GetProductCompatibilitiesRequest request = new GetProductCompatibilitiesRequest ();  
  4. Provide value for the required properties.
       
    request.productIdentifier = new ProductIdentifier();

       
    request.productIdentifier.ePID = "76715700";
  5. Create an object to the required response type. For example,
       
    GetProductCompatiblitiesResponse response = service. getProductCompatibilities (request);  
  6. Explore the response object for response data.    

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

 

 

Code in the Program.cs file

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using ProductAPI_Sample.ProductServiceWSDL;

 

namespace ProductAPI_Sample

{

    class Program

    {

        static void Main(string[] args)

        {

            CustomProductService service = new CustomProductService();

            service.Url = @"http://svcs.sandbox.ebay.com/services/marketplacecatalog/ProductService/v1";

 

            GetProductCompatibilitiesRequest request = new GetProductCompatibilitiesRequest();

            request.productIdentifier = new ProductIdentifier();

            request.productIdentifier.ePID = "76715700";

            PaginationInput page = new PaginationInput();

            page.entriesPerPageSpecified = true;

            page.entriesPerPage = 5;

            page.pageNumberSpecified = true;

            page.pageNumber = 1;

            request.paginationInput = page;

 

            GetProductCompatiblitiesResponse response = service.getProductCompatibilities(request);

            Console.WriteLine("Ack: " + response.ack);

            if (response.ack == AckValue.Success)

            {

                foreach (Product products in response.compatibilityDetails)

                {

                    Console.WriteLine("Property Name " + "\t" + "Value" + "\t");

                    foreach (PropertyValue property in products.productDetails)

                    {

                        if ((property.value[0].Item).GetType() == typeof(StringValue))

                        {

                            Console.WriteLine(property.propertyName + "\t" + ((StringValue)(property.value[0].Item)).value.ToString());

                        }

                        if ((property.value[0].Item).GetType() == typeof(NumericValue))

                        {

                            Console.WriteLine(property.propertyName + "\t" + ((NumericValue)(property.value[0].Item)).value.ToString());

                        }                       

                    }

                    Console.WriteLine();

                }

            }

 

            Console.ReadLine();

        }

    }

}

 

 

Code in the CustomProductService.cs file

using System;

using System.Collections.Generic;

using System.Text;

using ProductAPI_Sample.ProductServiceWSDL;

using System.Net;

 

namespace ProductAPI_Sample

{

    public class CustomProductService : ProductService

    {

        protected override System.Net.WebRequest GetWebRequest(Uri uri)

        {

            try

            {

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

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

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

                request.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "YOUR_APP_ID_HERE");

                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 console application to make getProductCompatibilities call.

The sample is developed using the VS 2005 and the latest ProductService WSDL

http://developer.ebay.com/webservices/product/latest/ProductService.wsdl

 

 

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