Visual Studio + Webservices + SOAP Headers

Suppose you have to consume a Webservice that requires you to provide a custom header. If you generate automatically the proxy with Visual Studio, you’ll soon discover that there’s no way to add an header or to access the SOAP request.
Ok, here’s what you have to do:

1) download the Web Services Enhancements 3.0 and reference microsoft.web.services3.dll in your project

2) change the base class of your proxy from System.Web.Services.Protocols.SoapHttpClientProtocol to Microsoft.Web.Services3.WebServicesClientProtocol

3) Use the newly exposed SoapContext property to add your custom headers and/or security tokens

Just keep in mind that if you ask Visual Studio to generate again the proxy, you’ll loose the changes…

Visual Studio + Webservices + SOAP Headers
Scroll to top