How to set HTTP Headers from client class inherited from SoapHttpClientProtocol
- by Alfred
I'm using a class MyClass inherited from SoapHttpClientProtocol (auto-generated in my project by creating a WebReference from a .wsdl file, representing a service).
Before calling a "WebMethod" of this service, I need to custom the http header of my request. I tried overloading the GetWebRequest() method of SoapHttpClientProtocol that way :
public partial class MyClass: System.Web.Services.Protocols.SoapHttpClientProtocol{
protected override WebRequest GetWebRequest(Uri uri) {
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
request.Headers.Add("MyCustomHeader", "MyCustomHeaderValue");
return request;
}
}
I was hoping that GetWebRequest was called in the constructor of MyClass, apparently it's not.
Could someone help me ?