How to Add Custom Http Header for C# Web Service Client Consuming Axis 1.4 Web Service

How to add custom Http Header for C# Web Service Client consuming Axis 1.4 Web service

It seems the original author has found their solution, but for anyone else who gets here looking to add actual custom headers, if you have access to mod the generated Protocol code you can override GetWebRequest:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net.WebRequest request = base.GetWebRequest(uri);
request.Headers.Add("myheader", "myheader_value");
return request;
}

Make sure you remove the DebuggerStepThroughAttribute attribute if you want to step into it.

Can you alter a web service header in c# program

In the other question you linked to, the code snippet provided is System.Net.WebRequest request = base.GetWebRequest(uri); while your error message refers to base.getWebRequest. Note that the G needs to be capitalized.

If this doesn't help, you need to show us the code that you have which is causing the problem.

java web service client, adding http headers

You can pass a map with custom headers to the BindingProvider (I believe you can set the MessageContext.HTTP_REQUEST_HEADERS property). Try creating an Authorization header and passing it in.

Set custom SOAP header using Axis 1.4

Maybe you can use org.apache.axis.client.Stub.setHeader method? Something like this:

MyServiceLocator wsLocator = new MyServiceLocator();
MyServiceSoap ws = wsLocator.getMyServiceSoap(new URL("http://localhost/MyService.asmx"));

//add SOAP header for authentication
SOAPHeaderElement authentication = new SOAPHeaderElement("http://mc1.com.br/","Authentication");
SOAPHeaderElement user = new SOAPHeaderElement("http://mc1.com.br/","User", "string");
SOAPHeaderElement password = new SOAPHeaderElement("http://mc1.com.br/","Password", "string");
authentication.addChild(user);
authentication.addChild(password);
((Stub)ws).setHeader(authentication);

//now you can use ws to invoke web services...

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;
}
}


Related Topics



Leave a reply



Submit