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
Serializable Classes and Dynamic Proxies in Ef - How
JSON.Net (De)Serialize Untyped Property
A Pattern for Self-Cancelling and Restarting Task
Removing the Delay After Keydown Event
How to Check If a Number Is Positive or Negative in C#
C# Constructing Parameter Query SQL - Like %
Can Unity Be Made to Not Throw Synchronizationlockexception All the Time
Comboboxes Are Linked for Some Reason
Xaml Gridview Itemtemplate Not Binding to Control
Switch Between Dotnet Core Sdk Versions
Execute Multiple Queries in Single Oracle Command in C#
Why "Decimal" Is Not a Valid Attribute Parameter Type
Windows.Forms.Panel 32767 Size Limit
Asmx Web Service How to Return JSON and Not Xml
How to Programmatically Limit My Program's CPU Usage to Below 70%
Read Big Txt File, Out of Memory Exception
Micro Optimization of a 4-Bucket Histogram of a Large Array or List