Web service: How to add SOAP header to a SOAP message?
I want to add a SOAP header but the webservice is not exposing a header in the WSDL.
The problem is that I have to communicate with a Web service that I didn't author. The service doesn't expose SOAP headers in the WSDL but I know the layout and format of the header(s).
The solution I worked out is to:
1. Generate a Web service proxy
2. Create a class that describes the SOAP header you will be sending:
[XmlRoot(Namespace = "http://ech.client.nl/vendor")]
public class VENDOR : SoapHeader
{
public string Value;
}
3. Add a public member variable to the proxy class named "vendorHeader":
public VENDOR vendorHeader;
4. Modify the method you are invoking and add the following attribute to that method:
[SoapHeader("vendorHeader", Direction = SoapHeaderDirection.In)]
5. Modify the body of the method call so that you create an instance of the member variable. Put this code before the "Invoke" code:
vendorHeader = new VENDOR();
vendorHeader.Value = "username and password";
That's it.
0 Response to "Web service: How to add SOAP header to a SOAP message?"
Post a Comment