Adding Custom Http Headers to Web Service Proxy

You should be able to do this by overriding the GetWebRequest method of the proxy class in a partial class in a separate file. After calling the base class method, you should be able to modify the returned HttpWebRequest however you like, then return it from the method:

public partial class MyServiceProxy {
    protected override WebRequest GetWebRequest(Uri uri) {
        HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
        // do what you will with request.
        return request;
    }
}

Leave a Comment