WSDL 1.1 (Web Service Description Language)
A WSDL file is an XML file which describes its associated web service. The WSDL XML file describes: where the web service is located, the methods available, parameters required and their return types. WSDLs are platform in-specific and can be consumed from any accessible environment, framework and/or language (Mac/Windows/Linux, Web Apps/Services, C#/C++/Python/Perl etc...)
Using the WSDL file, a consumer has enough information to query the underlying web services using one or many of it's associated operations. Most languages/frameworks have built-in or third party libraries available that can generate proxy classes based on the WSDL file (Another layer in front of the WSDL/Service you can query against using your chosen language. I.e. wsdl.exe for .NET or WSDL2Java for Java). This is only an option to make things easier, and is by no means mandatory.
Version History
WSDL 1.0 was introduced in 2000 and was developed through a collaboration by Microsoft, IBM and Ariba. The language was formalized in 2001 as version 1.1.
WSDL 2.0 became a W3C recommendation on June 2007. WSDL 1.2 was renamed to WSDL 2.0 because it has substantial differences from WSDL 1.1. The changes are:
Adding further semantics to the description language
Removal of message constructs
No support for operator overloading
PortTypes renamed to interfaces
Ports renamed to endpoint.
Offers binding to all HTTP Request methods (Not just GET and POST [WSDL 1.1]).. So it enabled better RESTful web services.
Most third-party vendors, however, have not adapted their offerings to support WSDL 2.0. For example, the Web Services Business Process Execution Language (WS-BPEL) uses WSDL 1.1.
Document Structure (One or many of these base four definitions may exist)
Code Snippet
- <definitions>
- <types>
- The data types used by the web service
- </types>
- <message>
- The messages used by the web service
- </message>
- <portType>
- The operations performed by the web service
- </portType>
- <binding>
- The communication protocols used by the web service
- </binding>
- <service>
- Information regarding the service endpoints.
- </service>
- </definitions>
End of Code Snippet
Note:
- A WSDL can contain extension elements. For example, it is also possible to group multiple services into one WSDL. However, the core principles behind the technology remain the same.
- It is common for one or many type, mesaage, portType or binding definitions to exist within one WSDL file.
Port Types (Interfaces in 2.0)
The portType section defines all operations available within the web service. It also defines the input, output and fault messages for each operation (A fault tag can only exist with an output tag). The input/output/fault message names are mapped onto message tag names, which describe the names and types of parameters used.
Example
Code Snippet
- <message name="AddMessage">
- <part name="parameter" element="ns:Add"/>
- </message>
- <message name="AddResponseMessage">
- <part name="parameter" element="ns:AddResponse"/>
- </message>
- <message name="AddFaultMessage">
- <part name="parameter" type="ns:String"/>
- </message>
- <portType name="MathInterface">
- <operation name="Add">
- <input message="y:AddMessage"/>
- <output message="y:AddResponseMessage"/>
- <fault message="y:AddFaultMessage"/>
- </operation>
- <operation name="Subtract">
- <input message="y:SubtractMessage"/>
- <output message="y:SubtractResponseMessage"/>
- <fault message="y:SubtractFaultMessage"/>
- </operation>
- <operation name="Multiply">
- <input message="y:MultiplyMessage"/>
- <output message="y:MultiplyResponseMessage"/>
- <fault message="y:MultiplyFaultMessage"/>
- </operation>
- <operation name="Divide">
- <input message="y:DivideMessage"/>
- <output message="y:DivideResponseMessage"/>
- <fault message="y:DivideFaultMessage"/>
- </operation>
- </portType>
End of Code Snippet
The above example defines a single portType/Interface with four operations (Add, Subtract, Multiply and Divide). These are all Request-response type operations (because they have input and output) that also include faults.
There are four different types of MEPs (Message exchange patterns) that exist when defining operations in WSDL files...
One-way
- Contains only an input message.
Request-response
- Contains an input message, followed by an output message (may contain a fault message)
Solicit-response
- Contains an output message, followed by an input message (may contain a fault message)
Notification
- Contains only an output message.
I will cover messages later in this article, but I have displays the tags here (For the Add operation only) to see how operations are mapped onto messages. AddFaultMessage takes a simple string type, however, complex types (Arrays, Lists, Custom Objects etc..) may exist which require definition in the Types section of the WSDL. Lets have a look at this next...
Types
The types section defines the data types that are used by the service. If the service uses only simple types I.e. Integers, Strings etc... then the types section is not required. WSDL types can also be reused across multiple services. The types section contains one or many schema tags. XML Schema's are the typical choice, however, WSDL 1.1 is not limited to this schema type.
Example
Code Snippet
- <types>
- <schema targetNamespace="http://example.com/weather.xsd" xmlns="http://www.w3.org/2000/10/XMLSchema">
- <xs:complexType name="MathInput">
- <xs:sequence>
- <xs:element name="x" type="xs:double"/>
- <xs:element name="y" type="xs:double"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="MathOutput">
- <xs:sequence>
- <xs:element name="result" type="xs:double"/>
- </xs:sequence>
- </xs:complexType>
- <xs:element name="Add" type="MathInput"/>
- <xs:element name="AddResponse" type="MathOutput"/>
- <xs:element name="Subtract" type="MathInput"/>
- <xs:element name="SubtractResponse" type="MathOutput"/>
- <xs:element name="Multiply" type="MathInput"/>
- <xs:element name="MultiplyResponse" type="MathOutput"/>
- <xs:element name="Divide" type="MathInput"/>
- <xs:element name="DivideResponse" type="MathOutput"/>
- </xs:schema>
- </types>
End of Code Snippet
From our previous example, we can see that all four operations map to eight messages (one input, one output, four operations). These 8 messages map on to these eight elements defined in the Types section. Above these elements, you can see two complex types have been defined: MathInput and MathOutput. When contrasting these examples in terms on O-O programming, you can think of a complexType as an Object; and x and y as properties of this object.
Messages (Do not exist in WSDL 2.0 - Operations refer to types directly)
Messages define the input and output of operations. They either map onto an element or a type (Both defined within the Types section). As discussed within the portType section previously, the operation decides which message is used for it's input and output.
Code Snippet
- <message name="AddMessage">
- <part name="parameter" element="ns:Add"/>
- </message>
- <message name="AddResponseMessage">
- <part name="parameter" element="ns:AddResponse"/>
- </message>
- <message name="SubtractMessage">
- <part name="parameter" element="ns:Subtract"/>
- </message>
- <message name="SubtractResponseMessage">
- <part name="parameter" element="ns:SubtractResponse"/>
- </message>
End of Code Snippet
Bindings
Bindings provides specific details on how the portType section will actually be transmitted over the wire. The bindings can be made available via. multiple transports: HTTP GET, HTTP POST and/or SOAP.
You can specify multiple bindings for a single portType. I.e. Making an operation available via GET, POST and SOAP.
The following example illustrates a SOAP/HTTP binding for the MathInterface portType (Defined above)...
Example
Code Snippet
- <definitions
- xmlns="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:y="http://example.org/math/"
- xmlns:ns="http://example.org/math/types/"
- targetNamespace="http://example.org/math/">
- ...
- <binding name="MathSoapHttpBinding" type="y:MathInterface">
- <soap:binding style="document"
- transport="http://schemas.xmlsoap.org/soap/http"/>
- <operation name="Add">
- <soap:operation soapAction="http://example.org/math/#Add"/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- <fault>
- <soap:body use="literal"/>
- </fault>
- </operation>
- ...
- </binding>
- ...
- </definitions>
End of Code Snippet
Binding Info
- The NAME of the binding must be given a unique name. I.e. MathSoapHttpBinding - so it can be referenced from within the WSDL.
- The TYPE of the binding must map onto the name of the portType (Interface WSDL 2.0)
soap:binding Info
- This element indicates that this is a SOAP 1.1 binding.
- The style of service is "document" (See section below on WSDL Styles)
- The transport protocol is HTTP
- The soap:operation element defines the SOAPAction HTTP header value for each operation
- The soap:body element defines how the message parts appear inside of the SOAP Body element (possible values include literal or encoded)
WSDL Styles
A WSDL SOAP binding can be either a Remote Procedure Call (RPC) style binding or a document style binding. A SOAP binding can also have an encoded use or a literal use.
Using document style in SOAP indicates that the body will contain an XML document, and that the message parts specify the XML elements that will be placed there. Using rpc style in SOAP indicates that the body will contain an XML representation of a method call and that the message parts represent the parameters to the method.
This gives you four style/use models:
RPC/encoded
RPC/literal
Document/encoded
Document/literal
The use attribute specifies the encoding that should be used to translate the abstract message parts into a concrete representation. In the case of 'encoded', the abstract definitions are translated into a concrete format by applying the SOAP encoding rules. In the case of 'literal', the abstract type definitions become the concrete definitions themselves (they're 'literal' definitions). In this case, you can simply inspect the XML Schema type definitions to determine the concrete message format. For example, the Add operation for the above document/literal binding looks like this on the wire:
Using literal definitions is much cleaner and easier for the tools to get right. Using the encoding rules has led to significant interoperability problems across toolkits. It also leads to weird situations like not being able to validate the wire-level message against the original schema definition (since it's abstract and not a true representation of the message)
More info on WSDL Styles here: http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
Service
The service element defines a collection of endpoints/ports that expose our bindings (Listed above). Each port must be given a name and assigned a binding.
Example
Code Snippet
- <definitions
- xmlns="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:y="http://example.org/math/"
- xmlns:ns="http://example.org/math/types/"
- targetNamespace="http://example.org/math/">
- ...
- <service name="MathService">
- <port name="MathEndpoint" binding="y:MathSoapHttpBinding">
- <soap:address
- location="http://localhost/math/math.asmx"/>
- </port>
- </service>
- </definitions>
End of Code Snippet
Full WSDL Example (For all above examples)
Code Snippet
- <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
- xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
- xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
- xmlns:y="http://example.org/math/"
- xmlns:ns="http://example.org/math/types/"
- targetNamespace="http://example.org/math/">
- <types>
- <xs:schema targetNamespace="http://example.org/math/types/"
- xmlns="http://example.org/math/types/"
- elementFormDefault="unqualified" attributeFormDefault="unqualified">
- <xs:complexType name="MathInput">
- <xs:sequence>
- <xs:element name="x" type="xs:double"/>
- <xs:element name="y" type="xs:double"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="MathOutput">
- <xs:sequence>
- <xs:element name="result" type="xs:double"/>
- </xs:sequence>
- </xs:complexType>
- <xs:element name="Add" type="MathInput"/>
- <xs:element name="AddResponse" type="MathOutput"/>
- <xs:element name="Subtract" type="MathInput"/>
- <xs:element name="SubtractResponse" type="MathOutput"/>
- <xs:element name="Multiply" type="MathInput"/>
- <xs:element name="MultiplyResponse" type="MathOutput"/>
- <xs:element name="Divide" type="MathInput"/>
- <xs:element name="DivideResponse" type="MathOutput"/>
- </xs:schema>
- </types>
- <message name="AddMessage">
- <part name="parameters" element="ns:Add"/>
- </message>
- <message name="AddResponseMessage">
- <part name="parameters" element="ns:AddResponse"/>
- </message>
- <message name="SubtractMessage">
- <part name="parameters" element="ns:Subtract"/>
- </message>
- <message name="SubtractResponseMessage">
- <part name="parameters" element="ns:SubtractResponse"/>
- </message>
- <message name="MultiplyMessage">
- <part name="parameters" element="ns:Multiply"/>
- </message>
- <message name="MultiplyResponseMessage">
- <part name="parameters" element="ns:MultiplyResponse"/>
- </message>
- <message name="DivideMessage">
- <part name="parameters" element="ns:Divide"/>
- </message>
- <message name="DivideResponseMessage">
- <part name="parameters" element="ns:DivideResponse"/>
- </message>
- <portType name="MathInterface">
- <operation name="Add">
- <input message="y:AddMessage"/>
- <output message="y:AddResponseMessage"/>
- </operation>
- <operation name="Subtract">
- <input message="y:SubtractMessage"/>
- <output message="y:SubtractResponseMessage"/>
- </operation>
- <operation name="Multiply">
- <input message="y:MultiplyMessage"/>
- <output message="y:MultiplyResponseMessage"/>
- </operation>
- <operation name="Divide">
- <input message="y:DivideMessage"/>
- <output message="y:DivideResponseMessage"/>
- </operation>
- </portType>
- <binding name="MathSoapHttpBinding" type="y:MathInterface">
- <soap:binding style="document"
- transport="http://schemas.xmlsoap.org/soap/http"/>
- <operation name="Add">
- <soap:operation soapAction="http://example.org/math/#Add"/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- <operation name="Subtract">
- <soap:operation soapAction="http://example.org/math/#Subtract"/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- <operation name="Multiply">
- <soap:operation soapAction="http://example.org/math/#Multiply"/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- <operation name="Divide">
- <soap:operation soapAction="http://example.org/math/#Divide"/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- </binding>
- <service name="MathService">
- <port name="MathEndpoint" binding="y:MathSoapHttpBinding">
- <soap:address location="http://localhost/math/math.asmx"/>
- </port>
- </service>
- </definitions>
End of Code Snippet
References
http://msdn.microsoft.com/en-us/library/ms996486.aspx
TODO: Add more info on WSDL 2.0
No comments:
Post a Comment