Java Reference
In-Depth Information
SOAP Web Service Client
Problem
You need to communicate with a SOAP-based client, and have heard that it's more complex
than REST services.
Solution
It is, but we'll get through it together, with help from JAX-WS. Get the WSDL. Process it
with wsimport . Call the generated service factory to obtain the service stub, and call that to
invoke the remote service.
Discussion
SOAP is the communications protocol used for XML Web Services. SOAP is not an ac-
ronym; it originally stood for “Simple Object Access Protocol” but by the time the standards
committee got through with it it was certainly not “simple,” and it was never really “object
oriented,” so they dropped the acronym but kept the name… Oh, and it's not really a “pro-
tocol” either—the protocol is usually HTTP or HTTPS. SOAP now is simply SOAP, al-
though using “simple” and “SOAP” in the same breath tends to draw guffaws from the REST
fans.
You need to get a copy of a “WSDL” (Web Services Description Language) document from
the server. You run it through a JAX-WS program called wsimport (included with the JDK).
You then invoke the generated service factory to get the service stub. Finally, call methods
on the service stub to access the remote service.
WSDL defines the service in immense detail. Think of it somewhat like a Java interface on
steroids. An interface tells you what methods can be called, their arguments, declared excep-
tions, and so on, but not where to find the service on the network, nor how to convert data in-
to a format that the other end can accept. A WSDL does all that, in a standardized (albeit
complex) way.
What's good about that is the client and the server do not have to be in the same program-
ming language, or on the same OS, or even the same CPU type. You can have a Java EE
server running the web service, and have clients on a mobile device (Android, iOS, Black-
Berry, Windows, etc.) or a Perl, Python, or Ruby client on a Linux, Mac, or BSD desktop.
The WSDL specifies all the formatting information so that word size issues and byte order-
Search WWH ::




Custom Search