WSDL 1.1

WSDL Overview

Defines an XML grammar for describing network services as collections of communication endpoints capable of exchanging messages.

Structures

Types

* A container for data type definitions using some type system (such as XSD).

<wsdl:types>
  <xsd:schema 
    targetNamespace="http://my.com/EchoServcie" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 
    <!-- Defines request element and complex type -->
    <xsd:complexType name="Echo">
      <xsd:sequence>
        <xsd:element name="message" type="xsd:string" 
          minOccurs="0" maxOccurs="1">
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Echo" type="tns:Echo"/>
 
    <!-- Defines response element and complex type -->
    <xsd:complexType name="EchoResponse">
      <xsd:sequence>
        <xsd:element name="return" type="xsd:string" 
          minOccurs="0" maxOccurs="1"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="EchoResonse" type="tns:EchoResponse"/>
 
  </xsd:schema>
</wsdl:types>

Message

* An abstract, typed definition of the data being communicated

<!-- Defines request message -->
<wsdl:message name="EchoRequest">
  <wsdl:part name="Echo" element="tns:Echo"/>
</wsdl:message>
 
<!-- Defines response message -->
<wsdl:message name="EchoResponse">
  <wsdl:part name="EchoResponse" element="tns:EchoResonse"/>
</wsdl:message>

Port Type

* An abstract *set* of operations supported by one or more endpoints.
* An operation is an abstract description of an action supported by the service.

<wsdl:portType name="EchoServicePortType">
  <wsdl:operation name="Echo">
    <wsdl:input message="tns:EchoRequest"/>
    <wsdl:output message="tns:EchoResponse"/>
  </wsdl:operation>
</wsdl:portType>

Binding

* a concrete protocol and data format specification for a particular port type.

<!-- Binds EchoServicePortType -->
<wsdl:binding name="EchoServiceSOAPBinding"
  type="tns:EchoServicePortType">
  <!-- Uses document style -->
  <!-- Uses SOAP over HTTP transport -->
  <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http" />
 
  <!-- SOAP binding details -->
  <wsdl:operation name="Echo">
    <soap:operation soapAction="http://my.com/EchoServcie/Echo" />
    <!-- Input Style -->
    <wsdl:input>
      <!-- SOAP body style -->
      <soap:body use="literal" />
    </wsdl:input>
 
    <!-- Output Style -->
    <wsdl:output>
      <!-- SOAP body style -->
      <soap:body use="literal" />
    </wsdl:output>
  </wsdl:operation>
 
</wsdl:binding>

Service

* a collection of related endpoints aka ports.
* a single endpoint/port is defined as a combination of a binding and a network address.

<!-- A service is a collection of endpoints -->
<wsdl:service name="EchoService">
  <!-- A single endpoint/port -->
   <!-- Uses binding definition -->
  <wsdl:port name="EchoServiceSOAPPort"
    binding="tns:EchoServiceSOAPBinding">
    <!-- And binds to address -->
    <soap:address location="http://my.com:8080/"/>
  </wsdl:port>
</wsdl:service>

Here is a complete Simple Echo Service WSDL

Factor SimpleEchoService.wsdl into Three XML Documents

Each XML document can have its own namespace.

Schema Doc

<?xml version="1.0"?>
<!-- 
  Define our schema with a namespace of 
  http://my.com/EchoService/Schema
-->
<xsd:schema 
  targetNamespace="http://my.com/EchoService/Schema"
  xmlns:tns="http://my.com/EchoService/Schema"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:complexType name="Echo">
    <xsd:sequence>
      <xsd:element name="message" type="xsd:string" 
        minOccurs="0"
        maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>
 
  <xsd:complexType name="EchoResponse">
    <xsd:sequence>
      <xsd:element name="return" type="xsd:string" 
        minOccurs="0"
        maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>
 
  <xsd:element name="Echo" type="tns:Echo"/>
  <xsd:element name="EchoResonse" type="tns:EchoResponse"/>
</xsd:schema>

Message and Port Type Doc

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
  Define message parts and port type in this document.
 -->
<wsdl:definitions name="EchoService" 
  targetNamespace="http://my.com/EchoService/Definitions" 
  xmlns:tns="http://my.com/EchoService/Definitions"
  xmlns:ess="http://my.com/EchoService/Schema"  
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <!-- Import our schema -->
  <wsdl:import location="SimpleEcho.xsd" 
    namespace="http://my.com/EchoService/Schema"/>
 
  <wsdl:message name="EchoRequest">
    <wsdl:part name="Echo" element="ess:Echo"/>
  </wsdl:message>
  <wsdl:message name="EchoResponse">
    <wsdl:part name="EchoResponse" element="ess:EchoResonse"/>
  </wsdl:message>
 
  <wsdl:portType name="EchoServicePortType">
        <wsdl:operation name="Echo">
          <wsdl:input message="tns:EchoRequest"/>
          <wsdl:output message="tns:EchoResponse"/>
        </wsdl:operation>
  </wsdl:portType>
</wsdl:definitions>

Service Doc

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
  Define our service in this document with a namespace of
  http://my.com/EchoService
 -->
<wsdl:definitions name="EchoService" 
  targetNamespace="http://my.com/EchoService"
  xmlns:tns="http://my.com/EchoService"
  xmlns:ess="http://my.com/EchoService/Schema"
  xmlns:esdef="http://my.com/EchoService/Definitions" 
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
 
  <!-- Import the definitions --> 
  <wsdl:import location="SimpleEcho.wsdl"
    namespace="http://my.com/EchoService/Definitions"></wsdl:import>
 
  <!-- Define binding for port type here -->
  <wsdl:binding name="EchoServiceSOAPBinding" 
    type="esdef:EchoServicePortType">
    <soap:binding style="document"
      transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="Echo">
      <soap:operation soapAction="http://my.com/EchoService/Echo" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
 
  <!-- Define service for the binding here -->
  <wsdl:service name="EchoService">
    <wsdl:port binding="tns:EchoServiceSOAPBinding" 
      name="EchoServiceSOAPPort">
      <soap:address location="http://my.com:8080/" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

wsimport Ant Task

Make sure to include the schema XML document in the wsimport binding.

<wsimport
  debug="true"
  verbose="${verbose}"
  keep="true"
  destdir="${build.classes.home}"
  package="com.my.echo.server"
  wsdl="${wsdl.file}">
  <binding dir="${basedir}/etc" 
  includes="SimpleEcho.xsd"/>
</wsimport>
This entry was posted in ws stds. Bookmark the permalink.