By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,070 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

How to add SOAP header to a SOAP message?

P: n/a
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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}

Nov 8 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
>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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}
Nov 8 '06 #2

P: n/a
You will need to add them manually before invoking the endpoint. Check out
this MSDN page for the answer:
http://msdn.microsoft.com/library/de...classtopic.asp

You'll need to know what the SOAP headers look like so that you can create
SoapHeader derived classes and then add instances of those classes to the
SoapHeaderCollection. You will need to use the SoapHeaderAttribute as well.

Hope that helps.

"Peter van der veen" wrote:
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.

On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}

Nov 8 '06 #3

P: n/a

And that is just the problem.

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

On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
<JD******@discussions.microsoft.comwrote:
>You will need to add them manually before invoking the endpoint. Check out
this MSDN page for the answer:
http://msdn.microsoft.com/library/de...classtopic.asp

You'll need to know what the SOAP headers look like so that you can create
SoapHeader derived classes and then add instances of those classes to the
SoapHeaderCollection. You will need to use the SoapHeaderAttribute as well.

Hope that helps.

"Peter van der veen" wrote:
>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.

On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
>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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}

Nov 9 '06 #4

P: n/a
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.

"Peter van der veen" wrote:
>
And that is just the problem.

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

On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
<JD******@discussions.microsoft.comwrote:
You will need to add them manually before invoking the endpoint. Check out
this MSDN page for the answer:
http://msdn.microsoft.com/library/de...classtopic.asp

You'll need to know what the SOAP headers look like so that you can create
SoapHeader derived classes and then add instances of those classes to the
SoapHeaderCollection. You will need to use the SoapHeaderAttribute as well.

Hope that helps.

"Peter van der veen" wrote:
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.

On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:

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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}


Nov 9 '06 #5

P: n/a
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.
On Thu, 9 Nov 2006 01:02:01 -0800, J. Dudgeon
<JD******@discussions.microsoft.comwrote:
>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.

"Peter van der veen" wrote:
>>
And that is just the problem.

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

On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
<JD******@discussions.microsoft.comwrote:
>You will need to add them manually before invoking the endpoint. Check out
this MSDN page for the answer:
http://msdn.microsoft.com/library/de...classtopic.asp

You'll need to know what the SOAP headers look like so that you can create
SoapHeader derived classes and then add instances of those classes to the
SoapHeaderCollection. You will need to use the SoapHeaderAttribute as well.

Hope that helps.

"Peter van der veen" wrote:

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.

On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:

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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}


Nov 14 '06 #6

P: n/a
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";

--------------

That's it.

"Peter van der veen" wrote:
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.
On Thu, 9 Nov 2006 01:02:01 -0800, J. Dudgeon
<JD******@discussions.microsoft.comwrote:
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.

"Peter van der veen" wrote:
>
And that is just the problem.

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

On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
<JD******@discussions.microsoft.comwrote:

You will need to add them manually before invoking the endpoint. Check out
this MSDN page for the answer:
http://msdn.microsoft.com/library/de...classtopic.asp

You'll need to know what the SOAP headers look like so that you can create
SoapHeader derived classes and then add instances of those classes to the
SoapHeaderCollection. You will need to use the SoapHeaderAttribute as well.

Hope that helps.

"Peter van der veen" wrote:

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.

On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:

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(headerElem ent);
} catch (SOAPException se) {
logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
}


Nov 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.