Java Reference
In-Depth Information
MessageFactory.newInstance().createMessage();
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";
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(out);
out.println("\nInvoking...");
//send the message as request to service and get response
SOAPMessage response = dispatch.invoke(soapMsg);
//Extract response content as DOM view
Document doc =
response.getSOAPBody().extractContentAsDocument();
NodeList isbnNodes = (NodeList)
doc.getElementsByTagName("lastName");
//just get by index; we know there's only one
String value = isbnNodes.item(0).getTextContent();
out.println("\nAuthor LastName=" + value);
//just show in the console for now
//response.writeTo(System.out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Here is the result of running the program:
Author LastName=Shakespeare
Search WWH ::




Custom Search