Five Styles of Bindings in WSDL
Five Binding Styles
* rpc/literal
* rpc/encoded
* doc/literal
* doc/encoded
* doc/literal/wrapped
References
* http://www.w3.org/TR/wsdl
* Which style of WSDL should I use?
* rpc/literal
* rpc/encoded
* doc/literal
* doc/encoded
* doc/literal/wrapped
* http://www.w3.org/TR/wsdl
* Which style of WSDL should I use?
Defines an XML grammar for describing network services as collections of communication endpoints capable of exchanging messages.
* 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>
* 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>
* 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>
* 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>
* 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
Each XML document can have its own namespace.
<?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>
<?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>
<?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>
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>
Overview
*WSDL is an XML document
*WSDL is used to describe web services
*Extensible (detail?)
Construct
*Types: defines data types using XSD (schema).
<types> <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2000/10/XMLSchema"> <element name="TradePriceRequest"> <complexType> <all> <element name="tickerSymbol" type="string"/> </all> </complexType> </element> <element name="TradePrice"> <complexType> <all> <element name="price" type="float"/> </all> </complexType> </element> </schema> </types>
*Message: an abstract, typed definition of data being communicated (parameter).
<message name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message>
*Operation: an abstract description of an action (method).
<operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation>
*Port Type: an abstract collection of operations (class).
<portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType>
*Binding: communication protocol (protocol).
<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="GetLastTradePrice"> <soap:operation soapAction="http://example.com/GetLastTradePrice"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding>
*Port: a single endpoint, i.e. binding + network address.
<port name="StockQuotePort" binding="tns:StockQuoteBinding"> <soap:address location="http://example.com/stockquote"/> </port>
*Service: a collection of endpoints (ports).
<service name="StockQuoteService"> <documentation>My first service</documentation> <port name="StockQuotePort" binding="tns:StockQuoteBinding"> <soap:address location="http://example.com/stockquote"/> </port> </service>
References
Great introduction to transaction