Using Web Service Definition Language Files

Before trying out this web service, you can test the availability of the SquareRootServerPublisher application with any web browser.

Open a browser and load the address http://127.0.0.1:5335/service?wsdl. The browser displays the XML file shown in Listing 22.4. This file is being served by the application that you just created.

This file is a service contract that’s written in Web Service Description Language (WSDL), an XML dialect for spelling out exactly how a web service functions so that servers and clients can make full use of it.

You don’t have to understand WSDL to create JAX-WS services and clients to access those services. It’s worthwhile to take a cursory look at the contents to get a picture for how SOAP- and REST-based web services operate.

Listing 22.4. A Web Service Description Language Contract


 1: <?xml version="1.0" encoding="UTF-8"?>
 2: <!— Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version
 3: is JAX-WS RI 2.2.2 in JDK 7. —>
 4: <!— Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version
 5: is JAX-WS RI 2.2.2 in JDK 7. —>
 6: <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 7: xmlns:tns="http://ws.java24hours.com/"
 8: xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 9: xmlns="http://schemas.xmlsoap.org/wsdl/"
10: targetNamespace="http://ws.java24hours.com/"
11: name="SquareRootServerImplService">
12: <types></types>
13: <message name="getSquareRoot">
14: <part name="arg0" type="xsd:double"></part>
15: </message>
16: <message name="getSquareRootResponse">
17: <part name="return" type="xsd:double"></part>
18: </message>
19: <message name="getTime"></message>
20: <message name="getTimeResponse">
21: <part name="return" type="xsd:string"></part>
22: </message>
23: <portType name="SquareRootServer">
24: <operation name="getSquareRoot" parameterOrder="arg0">
25: <input message="tns:getSquareRoot"></input>
26: <output message="tns:getSquareRootResponse"></output>
27: </operation>
28: <operation name="getTime" parameterOrder="">
29: <input message="tns:getTime"></input>
30: <output message="tns:getTimeResponse"></output>
31: </operation>
32: </portType>
33: <binding name="SquareRootServerImplPortBinding"
34: type="tns:SquareRootServer">
35: <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
36: style="rpc"></soap:binding>
37: <operation name="getSquareRoot">
38: <soap:operation soapAction=""></soap:operation>
39: <input>
40: <soap:body use="literal" 
41: namespace="http://ws.java24hours.com/"></soap:body>
42: </input>
43: <output>
44: <soap:body use="literal"
45: namespace="http://ws.java24hours.com/"></soap:body>
46: </output>
47: </operation>
48: <operation name="getTime">
49: <soap:operation soapAction=""></soap:operation>
50: <input>
51: <soap:body use="literal"
52: namespace="http://ws.java24hours.com/"></soap:body>
53: </input>
54: <output>
55: <soap:body use="literal"
56: namespace="http://ws.java24hours.com/"></soap:body>
57: </output>
58: </operation>
59: </binding>
60: <service name="SquareRootServerImplService">
61: <port name="SquareRootServerImplPort"
62: binding="tns:SquareRootServerImplPortBinding">
63: <soap:address location="http://127.0.0.1:5335/service"></soap:address>
64: </port>
65: </service>
66: </definitions>


A WSDL file 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.


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.


Lines 13–22 of the WSDL contract 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() method takes a double parameter and returns a double value.

The data types referenced in the contract are 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 specifically to Java.)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.163.62