This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Web Services and the fly likes Adding SOAP header to the SOAP message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Adding SOAP header to the SOAP message" Watch "Adding SOAP header to the SOAP message" New topic

Adding SOAP header to the SOAP message

Anup Bansal
Ranch Hand

Joined: Sep 12, 2006
Posts: 69
Hi ALl,

I am using AXIS 1.4 for the development of a webservice client. I am using WSAD 5.1 as the IDE. I have used the WSDL2Java tool to generate the Client stubs. The remote operation of the webservice that I need to invoke accepts an object as a parameter. Now this object will basically form the body part of the SOAP message.

Can anyone help me with the folowing:
I need to encrypt my SOAP message using XML digital signature. How can I add the header to the SOAP message after invoking the remote method. Can message handlers be used with AXIS?

Thanks & regards,
Raminder Singh
Ranch Hand

Joined: Mar 01, 2002
Posts: 72
Check this buddy.

SOAPHeaderElement auth = new SOAPHeaderElement("http://localhost/services/Odds","Authentication");

So the complete SOAP message will be as follows:

<?xml version="1.0" encoding="UTF-8"?>
xmlns:soapenv = ""
xmlns:xsd = ""
xmlns:xsi = "">
soapenv:actor = ""
soapenv:mustUnderstand = "0"
xmlns:ns1 = "http://localhost/services/Odds">
<ns1 asssword>xxxxx</ns1 asssword>
<GetXMLRaggruppamentiEsiti soapenv:encodingStyle = ""/>

Hope this will solve the purpose.
Anup Bansal
Ranch Hand

Joined: Sep 12, 2006
Posts: 69
Hi Raminder,

Thanks for the help. I am using the generated stubs to make the call to the webservice. In order to use the suggestion you have mentioned, I will have to modifiy the Stub class. Am I right?

Can I use the handlers to perform the same? If yes, how can I configure the handlers?

Thanks & regards,
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Adding SOAP header to the SOAP message
It's not a secret anymore!