WSDL Explained
WSDL Explained
WSDL (Web Services Description Language) is the XML contract that describes a SOAP service. It tells clients exactly what operations are available, what parameters they accept, and what they return.
Structure of a WSDL File
A WSDL document has several key sections:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<!-- XML Schema definitions for data types -->
<schema>
<element name="createOrder">
<complexType>
<sequence>
<element name="productName" type="string"/>
<element name="quantity" type="int"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="CreateOrderRequest">
<part name="parameters" element="tns:createOrder"/>
</message>
<message name="CreateOrderResponse">
<part name="parameters" element="tns:order"/>
</message>
<portType name="OrderService">
<operation name="createOrder">
<input message="tns:CreateOrderRequest"/>
<output message="tns:CreateOrderResponse"/>
</operation>
</portType>
<binding name="OrderServiceBinding" type="tns:OrderService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
</binding>
<service name="OrderService">
<port binding="tns:OrderServiceBinding" name="OrderPort">
<soap:address location="http://localhost:8080/orders"/>
</port>
</service>
</definitions>
The Five Sections
types - defines the data structures using XML Schema. message - defines the input and output messages. portType - groups operations into an interface. binding - specifies the protocol (SOAP over HTTP). service - provides the endpoint URL.
Using the WSDL to Generate a Client
The wsimport tool generates Java client code from a WSDL:
wsimport -keep -s src/main/java http://localhost:8080/orders?wsdl
This generates the service class, port type interface, and JAXB data classes. You can call the SOAP service as if it were a local Java method.
Document vs RPC Style
Document style sends full XML documents. RPC style sends method calls as XML. Document style is more flexible and is the recommended standard. Most modern SOAP services use document/literal style.
Key Points
- WSDL is the XML contract describing a SOAP service.
- It contains five sections: types, messages, portType, binding, and service.
- The
wsimporttool generates Java client code from a WSDL. - Document/literal style is the recommended standard for SOAP services.
- WSDL enables language-independent SOAP client generation.