Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding header to soap requests

 
Alexandru Gifei
Ranch Hand
Posts: 42
Java Linux Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a client side application in c# which is using non-.NET web services. I need to add a token to every request i make after i receive this token.
The header has to look like this:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header>
<ws:AuthToken xmlns:ws="http://wso2.com">
<token>96cb8826-e1c3-424f-9261-0ff342be67c4</token>
</ws:AuthToken>
</soapenv:Header>
<soapenv:Body>
....
</soapenv:Body></soapenv:Envelope>

How can i add this token programatically in the soap header to every request i make?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add a client-side webservice handler. You may want to read up on that.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally you'd use a WS-Security library that comes with all major SOAP stacks, and as Bosun said, that's what client-side handlers do.
 
Alexandru Gifei
Ranch Hand
Posts: 42
Java Linux Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to resolve this issue by creating a new web service client based on soap protocol. Then i added the token to SoapClientMessage by overriding the GetWriterForMessage method.
 
Anand Bansal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am able to achieve this. But I want to add a custom header tag inside a SOAP Header. It should not have a SOAP URI and any namespaces.

<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-9419978" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:Username>admin</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password></wsse:UsernameToken></wsse:Security>

<ABCHeader><MySubTag>textvalues</MySubTag></ABCHeader> ---------> This needs to be added.

</soapenv:Header>

Can someone help me out on this? I tried to add this through the below code and is adding extra information not required by me.

SOAPElement newHeader = soapheader.addChildElement("ABCHeader");
SOAPElement mySubTag = newHeader.addChildElement("MySubTag");
mySubTag.addTextNode("textvalues");

Output:
<soapenv:ABCHeader soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0"><soapenv:MySubTag>textValues</soapenv:MySubTag></soapenv:ABCHeader>


Expected Output:
<ABCHeader><MySubTag>textvalues</MySubTag></ABCHeader>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic