Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

320 HOUR 22:Creating Web Services with JAX-WS


47: </operation>
48: <operationname=”getTime”>
49: <soap:operationsoapAction=””></soap:operation>
50: <input>
51: <soap:bodyuse=”literal”
52: namespace=”http://ws.java24hours.com/”></soap:body>
53: </input>
54: <output>
55: <soap:bodyuse=”literal”
56: namespace=”http://ws.java24hours.com/”></soap:body>
57: </output>
58: </operation>
59: </binding>
60: <servicename=”SquareRootServerImplService”>
61: <portname=”SquareRootServerImplPort”
62: binding=”tns:SquareRootServerImplPortBinding”>
63: <soap:addresslocation=”http://127.0.0.1:5335/service”></soap:address>
64: </port>
65: </service>
66: </definitions>

A WSDLfile is called a service contract because it stipulates how a web
service can be reached, the messages that can be exchanged with the service,
and the data types of the information being transferred.
Lines 13–22 of the WSDLcontract define the web service’s methods, the
parameters of those methods, and the data returned in response. Take a
look over those lines to see if you can determine where it states that the
getSquareRoot()methodtakes a double parameter and returns a double
value.
The data types referenced in the contractare not Java data types. They’re
data types that are generalized for use by any programming language that
supports SOAP. (There’s nothing about web services that’s tailored specifi-
cally to Java.)

Creating a Web Service Client
In this section, you create SquareRootClient, a Java application that can call
the methods of the webservice you just created. The service must, of
course, be running for the client to connect to it.

LISTING 22.4 Continued

NOTE
Because a WSDL contract
defines a web service in such
specific detail,you can use it to
automate much of the process
of programming web services.
The Java Development Kit (JDK)
includes a command-line tool,
wsimport, that takes a WSDL file
as input and writes Java classes
to access the web service.

Free download pdf