Java Reference
In-Depth Information
The getBook method accepts a string ISBN code and returns the topic object that matches it.
In this example, you want to invoke the service without creating portable wrapper objects on
the client with a tool like wsimport . So, you'll write a file that contains a complete SOAP
envelope, and then read that into a SAAJ Dispatch to invoke the service. Here is the SOAP
message in your client, isbnMsg.txt:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<i:isbn xmlns:i="http://ns.soacookbook.com/catalog">12345</i:isbn>
</soap:Body>
</soap:Envelope>
Note that the line breaks are optional; you will be able to invoke your service successfully
whether you include them or not. I included them here for readability.
So, now create a dispatch client. There are a few steps involved. The listing in Example 5-4
represents a complete example.
Example5-4.ManuallyinvokingawebservicewithDispatchusingSOAPMessageinmes-
sage mode
import static java.lang.System.out;
import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
public class CatalogTest {
public void dispatchMsgIsbnTest() {
try {
URL wsdl =
new URL("http://localhost:8080/CatalogService/
Catalog?wsdl");
String ns = "http://ns.soacookbook.com/ws/catalog";
//Create the Service qualified name
String svcName = "CatalogService";
Search WWH ::




Custom Search