How to add SOAP header to a SOAP message?

  • Thread starter Peter van der veen
  • Start date
P

Peter van der veen

Hi

I have the following problem.

I'm calling a webservice from within a VB.net 2005 Windows program.
For this i got a WSDL file and loaded that in VB.
Until now i just call the webservice and everything works OK.

Now i need to add an extra attribute/header element to the SOAP header
before i contact the webservice.
The webservice needs this to be in the SOAP header.

Where and how do i do this? I have no clue at all.

From the company that runs the webservice i got an example code in
Java, but i have no idea where this had to be placed.


Hope that soemone can help me or can direct me in a direction to find
a solution

JAVA Code:
// Construct the header
QName headerName = new QName(" http://ech.client.nl/vendor",
"Vendor");
SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
headerElement.setValue("ECH Gui");
headerElement.setMustUnderstand(true);

try {
Message message = arg0.getCurrentMessage();
message.getSOAPHeader().addChildElement(headerElement);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}
 
P

Peter van der veen

To be more precisely.

The webservice i call is not a .NET webservice.
In the WSDL are no header elements defined.

To simplify the question.

I call a webservice and i want to add an SOAP header (with a
headerelement and a value) to the outgoing message.
 
P

Peter van der veen

And that is just the problem.

I want to add a SOAP header but the webservice is not exposing a
header in the WSDL.
 
J

J. Dudgeon

My understanding of your problem is that you want to communicate with some
Web service that you didn't author. This service doesn't expose SOAP headers
in the WSDL but you know the layout and format of the header(s).

If that is the case then the headers don't need to be defined in the WSDL.
As long as the Web service is accepting and processing the SOAP headers
correctly, then follow the instructions above and it should work.
 
P

Peter van der veen

I only know that i need to add a header with the name 'VENDOR' tha
must be in the namespace "http://ech.client.nl/vendor"
and that i have to give it a value.

After that i need to attach that header to the SOAP message.

But i'm just call a function in the WSDL so i do net see how to add
such a header to the message.
 
J

J. Dudgeon

That was already described in my previous post.

1. Generate a Web service proxy as you normally do.

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;

leave it set to null for now.

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 = "This is my value";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top