Java Reference
In-Depth Information
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";
QName isbnQName = new QName(iNs, elementName);
//Add the <isbn> element to the SOAP body
//as its only child
body.addBodyElement(isbnQName).setValue("12345");
//debug print what we're sending
soapMsg.writeTo(System.out);
} catch (SOAPException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
The code doesn't invoke any web service, it just creates a message that is suitable for sending
to some WSDL that requires a message in this format. Here is the result of running the pro-
gram:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<isbn xmlns="http://ns.soacookbook.com/catalog">12345</isbn>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
If there are no attachments on the message, it is just written out as XML. If there are attach-
ments on the message, a MIME-encoded byte stream is written. Also, the method throws an
IOException if it can't write to the given stream.
Search WWH ::




Custom Search