Java Reference
In-Depth Information
Creating a Web Service Client Based on an Existing
SOAP Envelope
Problem
You want to manually create a client to invoke a web service. You have a SOAP envelope in
a plain-text file, perhaps as the result of some XSL transformation.
Solution
Use the SAAJ 1.3 API to build your message by hand. Then use a Dispatch<T> to call the
service with your message. There are several steps involved:
1. Create a URL based on the WSDL location.
2. Create a QName object representing the service.
3. Create a QName object representing the port to invoke.
4. Create a Dispatch object using the port QName . Parameterize Dispatch on
javax.xml.soap.SOAPMessage to indicate that you will build the entire SOAP envelope
yourself and provide it to the Dispatch .
5. When creating the Dispatch , indicate Message for the mode and use SOAPMes-
sage.class as the data type.
6. Read in the text file containing a complete SOAP envelope for Message mode and use it
to create an instance of SOAPMessage .
7. Call the invoke method of your dispatch. Because your Dispatch is parameterized on
SOAPMessage , that is what you'll get back in response.
Discussion
Let's turn to the business at hand. It can be very tricky getting started, so I'll spell things out
along the way.
On the server side, you have an EJB web service with the definition as shown in Example 5-3 .
This is the service your client will invoke.
Example5-3.Catalog EJB web service
@WebService(serviceName="CatalogService", name="Catalog",
targetNamespace="http://ns.soacookbook.com/ws/catalog")
Search WWH ::




Custom Search