I am developing a SOAP Client in java.My SOAPRequest is given below :
SOAP Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://myWs.com/com" xmlns:re="http://myWs.com/myAlert">
<soapenv:Header>
<com:MYHeader>
<com:Auth>
<com:MyID>1312</com:MyID>
<com:Pwd>test213</com:Pwd>
</com:Auth>
</com:MYHeader>
</soapenv:Header>
<soapenv:Body>
<re:MyRequest>
<re:MyOrder>
<re:MyItems>
<re:ItemCode>TEST</re:ItemCode>
<re:ItemName>TEST</re:ItemName>
<re:ItemRef>TEST</re:ItemRef>
</re:MyItems>
</re:MyOrder>
</re:MyRequest>
</soapenv:Body>
</soapenv:Envelope>
I use Spring Framework's WebServiceTemplate to consume the SOAPService.But when i try it i find that the request object which is the body section goes perfectly.But the header section goes as null.My SOAP client is given below :
SOAPClient :
public Object callWebService(MyRequest request){
MyResponse myObj = (MyResponse)getWebServiceTemplate().marshalSendAndReceive("http://localhost:9000/MyServices/ws/soap/MyService", request,new WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) {
try {
SoapMessage soapMessage = (SoapMessage)message;
SoapHeader header = soapMessage.getSoapHeader();
StringSource headerSource = new StringSource("<MYHeader>\n<Auth>\n<MyID>1312</MyID>\n<Pwd>test213</Pwd>\n</Auth>\n</MYHeader>");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, header.getResult());
} catch (Exception e) {
System.out.println("ERROR : "+e);
}
}
});
MyResponse response= (MyResponse) myObj;
return myObj;
}
In the above the "request" has the body section of the SOAPRequest.Kindly let me know what i am missing here.Thanks in advance