Java Reference
In-Depth Information
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<isbn xmlns="http://ns.soacookbook.com/catalog">12345</isbn>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So, let's get to work building the envelope. For clarity, I included the entire method that builds
the SOAP envelope, uses an appropriate Dispatch<SOAPMessage> , dumps the contents of the
message to the console, and then invokes the server. This listing is shown in Example 5-1 .
Example5-1.Building a complete SOAP message manually
public void buildSoapEnv() {
try {
URL wsdl = new URL("http://localhost:8080/CatalogService/
Catalog?wsdl");
String ns = "http://ns.soacookbook.com/ws/catalog";
//Create the Service name
String svcName = "CatalogService";
QName svcQName = new QName(ns, svcName);
//Get a delegate wrapper
Service service = Service.create(wsdl, svcQName);
//Create the Port name
String portName = "CatalogPort";
QName portQName = new QName(ns, portName);
Dispatch<SOAPMessage> dispatch =
service.createDispatch(portQName,
SOAPMessage.class, Service.Mode.MESSAGE);
//Create the message
SOAPMessage soapMsg =
MessageFactory.newInstance().createMessage();
//Get the body from the envelope
SOAPPart soapPart = soapMsg.getSOAPPart();
SOAPEnvelope env = soapPart.getEnvelope();
SOAPBody body = env.getBody();
//Create a qualified name for the namespace of the
//objects used by the service.
String iNs = "http://ns.soacookbook.com/catalog";
String elementName = "isbn";
Search WWH ::




Custom Search