question

mbur1202 avatar image
0 Likes"
mbur1202 asked ·

How can I send HTTP Headers to the Shopping API? (ASP.NET)

I'm trying to add an HTTP header (containing an oAuth token) to my Shopping API request, but the format of the Shopping call is different from other APIs, and I can't see a clear way to add headers.

For example, with the Finding API I can create a Finding Client object and add headers to that, as follows:

(using the WSDL com.ebay.developer.Finding\FindingService.wsdl)


FindingServicePortTypeClient client = new FindingServicePortTypeClient();

OperationContextScope scope = new OperationContextScope(client.InnerChannel);

HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();

httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");

OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;


But with the Shopping API, there seems to be no obvious 'Client'-style object that I can create and add headers to, just a 'Shopping' object where I can specify the endpoint URL (with parameters), and methods to specify which call to make. There are also request and response type objects for the calls, but no obvious way to add headers to those either:

Here's my current code to access the Shopping API:

(using the WSDL http://developer.ebay.com/webservices/latest/ShoppingService.wsdl)


Shopping shop = new Shopping();

shop.Url = "http://open.api.ebay.com/shopping?callname=GetCategoryInfo&siteId=0&version=987";

GetCategoryInfoRequestType request = new GetCategoryInfoRequestType();

GetCategoryInfoResponseType response = new GetCategoryInfoResponseType();

request.CategoryID = "115280";

response = shop.GetCategoryInfo(request);


I've already followed and read all of the links in the API documentation, and while they all say that HTTP headers can be sent to the Shopping API, none explain how to do it.

As you can probably tell I'm not the most experienced developer, so any help would be greatly appreciated. Thanks.

shopping apiheader-request-http
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
mbur1202 avatar image
0 Likes"
mbur1202 answered ·

I found the answer. Basing a custom class on the WSDL-returned Shopping class itself lets you add custom headers by overriding the GetWebRequest method.

Full explanation and code in this blog post:

https://docs.microsoft.com/en-us/archive/blogs/davidklinems/accessing-a-webservices-webrequest-and-webresponse-in-netcf

Replace:

public class MyCustomWebService : MyWebService

With:

public class MyCustomWebService : Shopping

(also remove the references to 'Object' - I guess that was an old .NET requirement? The above article was written in 2005)

·
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.