Engineering Full Stack Apps with Java and JavaScript
WSDL stands for Web service Description Language.
A WSDL document is a contract between a SOAP–based web service and its consumers.
A WSDL document provides critical information such as service endpoint, service operations, data types required for operations, description of messages exchanged, and underlying service pattern (request/response, solicit/response etc).
The WSDL document is useful for both creating and executing clients against a web service.
The root element in a WSDL is named definitions as the WSDL provides definitions grouped into various sections like:
types section
message section
portType section
binding section
service section
Example:
The types section provides data type definitions under some data type system such as XML schema.
The types section can hold, points to, or imports an XSD.
If the types section is empty, then the service uses only simple data types such as xsd:string and xsd:long.
The types section is optional.
Although the WSDL 2.0 specification allows for alternatives to XML schema, XML schema is the default and the dominant type system used in WSDL.
Example:
The message section defines the messages.
Message is an abstract, typed definition of the data being communicated.
All input parameters for a web service operation (method) are considered together as one input message.
At runtime each message is a SOAP document.
The order of the messages indicates the service pattern.
For example the message order in/out indicates the request/response pattern.
Example:
The port Type section groups the operations that the web service delivers,
Operation is an abstract description of an action supported by the web service.
Each operation having one or more messages.
An input message means input to the web service and output message means messages from a web service.
All input parameters for a web service operation (method) are bundled together as one input message.
These messages are also defined separately in the messages section.
At runtime each message is a SOAP document.
The portType section presents the services as named operations.
Operations are named after methods annotated as @WebMethod.
The WSDL portType presents the service operations abstractly but provides no implementation details.
A web service’s portType is similar to a java interface that, it presents the service abstractly, with no implementation details.
Example:
A WSDL binding provides concrete details about the service.
Specify implementation details of a service defined abstractly in the potType section :
The transport protocol to be used in sending and receiving SOAP messages.
The style of the service – rpc or document
The data format to be used in the SOAP message – literal and encoded.
Example:
The service section list one or more port elements.
A port consists of a portType (interface) together with a corresponding binding (implementation).
Service section specifies one or more end points at which the service’s functionality is available.
A service endpoint url is contained in the location attribute of <soap:address>, which is inside the service section.
The service endpoint url informs clients about where the service can be accessed.
Example:
Application exceptions can be mapped to faults in WSDL.
Fault elements may come in places such as:
Within a message element as a part:
<part name="fault" element="tns:MissingName" />
As a child of operation element within portType section.
<fault message="tns:MissingName" name="MissingName" />
As a child of operation element within binding section
<fault name="MissingName">
<soap:fault name="MissingName" use="literal" />
</fault>
Example: Try it out yourself in coming lab.
WSDL is platform and language neutral.
A WSDL generated by a c# program can be used to generate a Java web service.
With WSDL and XSD, the definition of the message can travel with the message.
Though a wsdl provides details on how to invoke a service, it does not contain information about the use of the service.
Programmer should be aware about the use of a service.