Find the answer to your question
Advanced Search
How to consume and use ProductMetadataService using .NET framework
- Add a web reference to the ProductMetadataService WSDL
http://developer.ebay.com/webservices/product-metadata/latest/ProductMetadataService.wsdl - Create a class that derives from ProductMetadataService class. For example, “CustomProductService.cs”.
Override the GetWebRequest method and set the HTTP request headers such as protocol, operationName, serviceName, securityAppName. - Create an object for the required request type. For example,
GetProductSearchValuesBulkRequest request = new GetProductSearchValuesBulkRequest(); - Provide value for the required properties.
request.categoryId = "33707"; - Create an object to the required response type. For example,
GetCompatibilitySearchValuesBulkResponse response = new GetCompatibilitySearchValuesBulkResponse();
res = service.getCompatibilitySearchValuesBulk(req); - Explore the response object for response data.
The following is the code sample for getCompatibilitySearchValuesBulk call using C#.NET
Code in the Program.cs file |
using System; using System.Collections.Generic; using System.Text; using ProductMetadata_Sample.com.ebay.developer;
namespace ProductMetadata_Sample { class Program { static void Main(string[] args) { try { CustomProductService service = new CustomProductService(); service.Url = @"http://svcs.ebay.com/services/marketplacecatalog/ProductMetadataService/v1";
GetProductSearchValuesBulkRequest req = new GetProductSearchValuesBulkRequest(); req.categoryId = "33707"; string[] strPropertyName = {"Year", "Make", "Model" }; req.propertyName = strPropertyName; // Setting Year Property filter PropertyValue pVal = new PropertyValue(); pVal.propertyName = "Make"; Value val = new Value(); StringValue strValue = new StringValue(); strValue.value = "Honda"; val.Item = strValue; Value[] vals = { val }; pVal.value = vals;
PropertyValue[] propertyValues = { pVal }; req.propertyFilter = propertyValues;
GetCompatibilitySearchValuesBulkResponse res = new GetCompatibilitySearchValuesBulkResponse(); res = service.getCompatibilitySearchValuesBulk(req);
if (res.ack == AckValue.Success) { Console.WriteLine("Ack: " + res.ack.ToString()); foreach (PropertyNameValue pnv in res.propertyValuesTree.childPropertyNameValue) { Console.WriteLine("PropertyName: " + pnv.propertyName); Console.WriteLine(((StringValue)(pnv.value.Item)).value); } } else { foreach (ErrorData error in res.errorMessage) { Console.WriteLine("ErrorID: " + error.errorId); Console.WriteLine("Message: " + error.message); } } } catch (Exception ex) { throw ex; } Console.ReadLine(); } } }
|
Code in the CustomProductService.cs file |
using System; using System.Collections.Generic; using System.Text; using ProductMetadata_Sample.com.ebay.developer; using System.Net;
namespace ProductMetadata_Sample { public class CustomProductService : ProductMetadataService { protected override System.Net.WebRequest GetWebRequest(Uri uri) { try { HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri); request.Headers.Add("X-EBAY-SOA-SERVICE-NAME", "ProductMetadataService"); request.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "getCompatibilitySearchValuesBulk"); request.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "YOUR_APP_ID"); request.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-MOTOR"); return request; } catch (Exception ex) { throw ex; } } } }
|
Note:
sample is developed using the VS 2005 and the latest ProductService WSDL http://developer.ebay.com/webservices/product-metadata/latest/ProductMetadataService.wsdl