1

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 ?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Alfred
  • 11
  • 1
  • 2
  • Thanks for your answers, that's helping. Unfortunately, if what you say is true (and I don't doubt it ;)), that means the service should be able to use my custom header, and it doesnt' (apparently)... After calling GetWebRequest(), is there an other method called, one which could (by any means) clear existing headers ? –  Jan 11 '11 at 20:48
  • I've added something similar to my SoapHttpClientProtocol implementation and it doesn't appear to actually add headers, or at least the service does not recognize them. Have you made any progress on this? – Russell Myers Apr 01 '11 at 20:21

2 Answers2

0

GetWebRequest is called when the proxy needs to get a web request.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
0

Right, the GetWebRequest virtual should be called each time a web method is invoked.

alexdej
  • 3,751
  • 23
  • 21