开发者

How to set HTTP Headers from client class inherited from SoapHttpClientProtocol

开发者 https://www.devze.com 2023-02-04 04:33 出处:网络
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).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消