Java Reference
In-Depth Information
System.out.printf("%n");
return soapMessage;
}
This piece of code will add a body to your SOAP message containing a GetQuote element ( SERVICE_
METHOD ). Within this XML tag, you add another element— symbol —with your provided stock quote
as the content.
The use of the QName object to add an XML element is a bit peculiar. The reason for this is that the
web service specifies that you need to add a GetQuote element, which looks like this:
<GetQuote xmlns=" http://www.webserviceX.NET/">...</Ge tQuote>
And not just:
<GetQuote>...</GetQuote>
If you use the following piece of code to construct your message:
// Construct the SOAP "body" with the method arguments
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement bodyElement = soapBody.addChildElement(SERVICE_METHOD);
SOAPElement soapBodyArgument1 = bodyElement.addChildElement("symbol");
soapBodyArgument1.addTextNode(stockSymbol);
You get the following request message—which looks okay:
<SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<GetQuote><symbol>IBM</symbol></GetQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But the server still responds with an “exception” reply. Again, servers can be very picky about how
they parse request messages, so take care to construct messages exactly as indicated by the service
provider.
With your code, however, you now see the following interchange happening:
Sending SOAP request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<GetQuote xmlns=" http://www.webserviceX.NET/">
<symbol>IBM</symbol>
</GetQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Search WWH ::




Custom Search