Basic WSDL Example: HelloService.wsdl - Page 2
April 3, 2002
To make the previously described WSDL concepts as concrete as
possible, let's examine our first sample WSDL file.
Example
6-1 provides a sample HelloService.wsdl document.
The document describes the HelloService from Chapter 4.
As you may recall, the service provides a single publicly
available function, called sayHello. The function
expects a single string parameter, and returns a single string greeting. For
example, if you pass the parameter world, the
service returns the greeting, "Hello, world!"
Example 6-1: HelloService.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="HelloService"
targetNamespace="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://localhost:8080/soap/servlet/rpcrouter"/>
</port>
</service>
</definitions>
The WSDL elements are discussed in the next section of this
chapter. As you examine each element in detail, you may want to refer to Figure
6-2, which summarizes the most important aspects of Example
6-1.
Figure 6-2. A bird's-eye view of HelloService.wsdl
|
|
definitions
The definitions element specifies
that this document is the HelloService. It also
specifies numerous namespaces that will be used throughout the remainder of
the document:
<definitions name="HelloService"
targetNamespace="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
The use of namespaces is important for differentiating elements,
and it enables the document to reference multiple external specifications,
including the WSDL specification, the SOAP specification, and the XML Schema
specification.
The definitions element also
specifies a targetNamespace attribute. The targetNamespace is a convention of XML Schema that
enables the WSDL document to refer to itself. In Example
6-1, we specified a targetNamespace of http://www.ecerami.com/wsdl/HelloService.wsdl. Note,
however, that the namespace specification does not require that the document
actually exist at this location; the important point is that you specify a
value that is unique, different from all other namespaces that are defined.
Finally, the definitions element
specifies a default namespace: xmlns=http://schemas.xmlsoap.org/wsdl/.
All elements without a namespace prefix, such as message or portType, are
therefore assumed to be part of the default WSDL namespace.
Web Services Essentials
Web Services Essentials
Basic WSDL Example: HelloService.wsdl (cont.) - Page 3
|