22 Building SOA-based Solutions for IBM System i Platform
3.4 Web services description: WSDL
A WSDL document describes a Web service: Web service location, methods, and method
parameters. Example 3-4 shows a sample JavaBean implementation. Notice that this Web
service has one method convertTemp that has an input String parameter and output String
parameter.
Example 3-4 Sample JavaBean implementation
public class TempConversionService {
public String convertTemp(String tempIn){
Double tempFahrenheit = new Double(tempIn);
// Convert temperature
Double tempCelsius = new Double ((5/9)*(tempFahrenheit.doubleValue()-32));
// Return a String value
return tempCelsius.toString();
}
}
Example 3-5 shows a WSDL file that the WebSphere Development Studio client for iSeries
Web services wizard generated for this JavaBean. While the document can seem
complicated at a first glance, you can still see familiar elements from the Web service
implementation: Web service method name and parameter definitions. At the end of the
document you find the following Web services location:
<wsdlsoap:address location=
"http://localhost:9080/SimpleWS/services/TempConversionService"/>
Notice that the generated URL points to localhost. This URL is the only part of the WSDL
document that you need to change before deploying the Web service to the server and
sending WSDL to the Web service client developer. You need to replace localhost and the
default port with the host name of your server and WebSphere Application Server port.
Example 3-5 Sample WSDL file
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://services.ibm.com"
xmlns:impl="http://services.ibm.com" xmlns:intf="http://services.ibm.com"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="http://services.ibm.com"
xmlns="http://www.w3.org/2001/XMLSchema" xmlns:impl="http://services.ibm.com"
xmlns:intf="http://services.ibm.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<element name="convertTempResponse">
<complexType>
<sequence>
<element name="convertTempReturn" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
Chapter 3. Web services technology stack 23
<element name="convertTemp">
<complexType>
<sequence>
<element name="tempIn" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="convertTempRequest">
<wsdl:part element="impl:convertTemp" name="parameters"/>
</wsdl:message>
<wsdl:message name="convertTempResponse">
<wsdl:part element="impl:convertTempResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="TempConversionService">
<wsdl:operation name="convertTemp">
<wsdl:input message="impl:convertTempRequest" name="convertTempRequest"/>
<wsdl:output message="impl:convertTempResponse"
name="convertTempResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TempConversionServiceSoapBinding"
type="impl:TempConversionService">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="convertTemp">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="convertTempRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="convertTempResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TempConversionServiceService">
<wsdl:port binding="impl:TempConversionServiceSoapBinding"
name="TempConversionService">
<wsdlsoap:address
location="http://localhost:9080/SimpleWS/services/TempConversionService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The WSDL file is sometimes called a
contract between a Web service and a Web service
client. After you create a contract, your goal should be not to introduce any changes to it.
Otherwise, the communication between a Web service client and a Web service will be
broken. You
can change Web service implementation (for example, change the way you
calculate temperature conversion). However, if you change your method of signature (method
name or parameter types), you will break the contract. Changing Web service location will not
break the contract. Just remember to notify the Web service client of Web service URI
change.

Get Building SOA-based Solutions for IBM System i Platform now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.