Web Services Example: Creating a WSDL file

The Web Services Description Language file provides the model for describing the web service.

Guide to reading this example:   Lines such as the following, typed in Courier font, are parts the WSDL file:

    <?xml version="1.0"?>

All other lines are comments describing the code.  The sum of the code shown here makes up a complete, although simplified, WSDL file.

 

The file commonly starts with a header which includes links to the XML schema.  To adapt the following header to your own system, replace every entry that reads "localhost" with the fully qualified domain name of your own server.  ('localhost' will probably work on your system for testing purposes)

Note: XML requires that the target Namespace be a globally unique identifier. Common practice would be to use a fully qualified domain name here.  "localhost" only works for our example because the application is running on the same computer as the "remote" CGI script.

 

<?xml version="1.0"?>

<wsdl:definitions name="TagQueryServices"

  targetNamespace="http://localhost/"

  xmlns:tns="http://localhost/"

  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

  xmlns:s="http://www.w3.org/2001/XMLSchema">

 

After the header comes a section describing the WSDL types.  This describes the target namespace (again, localhost is used here - substitute your own domain), and the expected input and output variables.  In this case, when a request is made for 'TagName' a response will be generated that includes 'TagValue' and a 'ReturnCode'.   The TagName is expected to be of type String.  The TagValue will be of type Float and the ReturnCode will be an integer.

 

  <wsdl:types>

    <s:schema

          targetNamespace="http://localhost/">

      <s:import

          namespace="http://schemas.xmlsoap.org/soap/encoding/" />

      <s:import

          namespace="http://schemas.xmlsoap.org/wsdl/" />

      <s:complexType

          name="GetTagValueIn">

        <s:sequence>

          <s:element

              minOccurs="1"

              maxOccurs="1"

              name="TagName"

              type="s:string" />

        </s:sequence>

      </s:complexType>

      <s:complexType name="GetTagValueOut">

        <s:sequence>

          <s:element

              minOccurs="1"

              maxOccurs="1"

              name="TagValue"

              type="s:float" />

          <s:element

              minOccurs="1"

              maxOccurs="1"

              name="ReturnCode"

              type="s:int" />

        </s:sequence>

      </s:complexType>

    </s:schema>

  </wsdl:types>

 

The expected SOAP messages are defined next:  In this case there are only two: GetTagValueInput (the request) and GetTagValueOutput (the response).

 

  <wsdl:message name="GetTagValueInput">

    <wsdl:part

           name="request"

           type="tns:GetTagValueIn" />

  </wsdl:message>

  <wsdl:message name="GetTagValueOutput">

    <wsdl:part

           name="response"

           type="tns:GetTagValueOut" />

  </wsdl:message>

 

The PortType section includes a supported set of operations, in this case "GetTagValue".

Each operation lists the input and the output messages of the operation.

 

  <wsdl:portType name="QueryServicesPort">

    <wsdl:operation

           name="GetTagValue"

           parameterOrder="request response">

      <wsdl:input

             message="tns:GetTagValueInput"/>

      <wsdl:output

             message="tns:GetTagValueOutput"/>

    </wsdl:operation>

  </wsdl:portType>

 

The Binding section ties the SOAP calls to the supported operations. Note the use of the 'localhost' address in this section.  Again, you will need to change this to the domain of your own server.  Also to be noted is the reference to the port defined above.

 

  <wsdl:binding

         name="QueryServicesSoapBinding"

         type="tns:QueryServicesPort">

    <soap:binding

           style="document"

           transport="http://schemas.xmlsoap.org/soap/http"/>

    <wsdl:operation

           name="GetTagValue">

      <soap:operation

             soapAction="http://localhost/GetTagValue"

             style="rpc"/>

      <wsdl:input>

        <soap:body

               use="encoded"

               namespace="http://localhost/"

               encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />

      </wsdl:input>

      <wsdl:output>

        <soap:body

               use="encoded"

               namespace="http://localhost/"

               encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />

      </wsdl:output>

    </wsdl:operation>

  </wsdl:binding>

 

At the end of the WSDL file is the most interesting part.  This small block of code ties the operations defined above to the actual realm that we will be calling from our external program.  Note the name - this will appear again in the next step when we create the VTS module to handle the requests.  Also note the appearance of the realm name after the domain when defining the address for the SOAP requests.

 

  <wsdl:service name="TagQueryServices">

    <wsdl:port

           name="QueryServicesPort"

           binding="tns:QueryServicesSoapBinding">

      <soap:address

             location="http://localhost/QueryServicesRealm/"/>

    </wsdl:port>

  </wsdl:service>

 

Finally, to finish the file we must close the tag that opened it all, like so:

 

</wsdl:definitions>

 

Next step:  Creating the VTS  Web Services Module