You may have seen my previous post on SOAP vs. REST call. Now a day companies are moving to REST service calls but still there are majority of companies still uses SOAP over REST. This tutorial explains basic of WSDL (Web Service Description Language).
If you have any of below question then you are at right place:
- What is Web Services Description Language (WSDL)?
- WSDL Tutorial
- Web Services Description Language (WSDL) Explained
- Examples of WSDL – Web Service Description Language
Web Services Description Language (WSDL)
In Java Web Development World, WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information.
The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services).
WSDL is extensible to allow description of endpoints and their messages regardless of what message formats or network protocols are used to communicate, however, the only bindings described in this document describe how to use WSDL
in conjunction with SOAP 1.1, HTTP GET/POST, and MIME.
Another must read:
- Create Sample WSDL in Eclipse and Generate Client
- How to build RESTful Service with Java using JAX-RS and Jersey (Example)
In other words: A WSDL document defines services as collections of network endpoints, or ports
. In WSDL, the abstract definition of endpoints and messages is separated from their concrete network deployment or data format bindings. This allows the reuse of abstract definitions: messages
, which are abstract descriptions of the data being exchanged, and port types which are abstract collections of operations.
The concrete protocol and data format specifications for a particular port type constitutes a reusable binding
. A port is defined by associating a network address with a reusable binding, and a collection of ports define a service.
Hence, a WSDL document uses the following elements in the definition of network services:
Types
– a container for data type definitions using some type system (such asXSD
).Message
– an abstract, typed definition of the data being communicated.Operation
– an abstract description of an action supported by the service.Port Type
–an abstract set of operations supported by one or more endpoints.Binding
– a concrete protocol and data format specification for a particular port type.Port
– a single endpoint defined as a combination of a binding and a network address.Service
– a collection of related endpoints.
Element | Description |
---|---|
<types> | Defines the (XML Schema) data types used by the web service |
<message> | Defines the data elements for each operation |
<portType> | Describes the operations that can be performed and the messages involved. |
<binding> | Defines the protocol and data format for each port type |
Example: SOAP 1.1 Request/Response via HTTP
Sample XML WSDL Document.
<?xml version="1.0"?> <definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl" xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <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 name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message> <portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType> <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> <service name="StockQuoteService"> <documentation>My first service</documentation> <port name="StockQuotePort" binding="tns:StockQuoteBinding"> <soap:address location="http://example.com/stockquote"/> </port> </service> </definitions>
SOAP 2.0 WSDL Example:
<!-- Crunchify's example of WSDL 2.0 --> <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.w3.org/ns/wsdl" xmlns:tns="http://www.tmsws.com/wsdl20sample" xmlns:whttp="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsoap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://www.tmsws.com/wsdl20sample"> <!-- Abstract type --> <types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.tmsws.com/wsdl20sample" targetNamespace="https://crunchify.com/wsdl20"> <xs:element name="request"> ...add your code here... </xs:element> <xs:element name="response"> ...add your code here... </xs:element> </xs:schema> </types> <!-- Abstract interfaces --> <interface name="CrunchifyItem"> <fault name="ErrorDescription" element="tns:response"/> <operation name="Get" pattern="http://www.w3.org/ns/wsdl/in-out"> <input messageLabel="In" element="tns:request"/> <output messageLabel="Out" element="tns:response"/> </operation> </interface> <!-- Concrete Binding Over HTTP --> <binding name="HttpBinding" interface="tns:CrunchifyItem" type="http://www.w3.org/ns/wsdl/http"> <operation ref="tns:Get" whttp:method="GET"/> </binding> <!-- Concrete Binding with SOAP--> <binding name="SoapBinding" interface="tns:CrunchifyItem" type="http://www.w3.org/ns/wsdl/soap" wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP/" wsoap:mepDefault="http://www.w3.org/2003/05/soap/mep/request-response"> <operation ref="tns:Get" /> </binding> <!-- Web Service offering endpoints for both bindings--> <service name="ServiceOne" interface="tns:CrunchifyItem"> <endpoint name="HttpEndpoint" binding="tns:HttpBinding" address="http://www.example.com/rest/"/> <endpoint name="SoapEndpoint" binding="tns:SoapBinding" address="https://crunchify.com/soap/"/> </service> </definitions>
Factory Design Pattern explained with Example.
Let me know if you have any questions.