I'm using a class MyClass inherited from SoapHttpClientProtocol (auto-generated in my project by creating a WebReference from a .wsdl file, representing开发者_Python百科 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 ?
GetWebRequest is called when the proxy needs to get a web request.
Right, the GetWebRequest virtual should be called each time a web method is invoked.
精彩评论