WSDL - Elements of a WSDL Document
Elements of a WSDL Document
A WSDL document describes what a web service does, how to access it, and where to find it. It is written in XML and is made up of several main parts:
1. <definitions>
-
The root element of the WSDL document.
-
It defines the name of the web service and the XML namespaces used.
Example:
<definitions name="StudentService"
targetNamespace="http://example.com/student"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://example.com/student">
2. <types>
-
Defines the data types (using XML Schema) that will be used in the messages.
-
This is where you describe complex inputs and outputs.
Example:
<types>
<xsd:schema targetNamespace="http://example.com/student">
<xsd:element name="StudentName" type="xsd:string"/>
</xsd:schema>
</types>
3. <message>
-
Defines the input and output messages for each operation.
-
Each message can have one or more parts (parameters).
Example:
<message name="GetStudentRequest">
<part name="studentId" type="xsd:int"/>
</message>
<message name="GetStudentResponse">
<part name="studentName" type="xsd:string"/>
</message>
4. <portType>
-
Describes the operations (methods/functions) provided by the web service.
-
It defines what messages are used for input and output.
Example:
<portType name="StudentPortType">
<operation name="GetStudent">
<input message="tns:GetStudentRequest"/>
<output message="tns:GetStudentResponse"/>
</operation>
</portType>
5. <binding>
-
Specifies how the operations are transmitted (e.g., using SOAP over HTTP).
-
It connects the abstract operations to the actual protocol.
Example:
<binding name="StudentBinding" type="tns:StudentPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetStudent">
<soap:operation soapAction="getStudentAction"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
6. <service>
-
Defines the endpoint URL where the service is located.
-
It uses the binding to connect to a real web address.
Example:
<service name="StudentService">
<port name="StudentPort" binding="tns:StudentBinding">
<soap:address location="http://example.com/studentservice"/>
</port>
</service>