How to set HTTP Headers from client class inherited from SoapHttpClientProtocol
Posted
by
Alfred
on Stack Overflow
See other posts from Stack Overflow
or by Alfred
Published on 2011-01-11T19:15:44Z
Indexed on
2011/01/11
20:54 UTC
Read the original article
Hit count: 541
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 ?
© Stack Overflow or respective owner