Open In App

WSDL <definitions> Element

Last Updated : 17 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

WSDL <definitions> element is the root element of the WSDL document. It binds the entire details of the services that are offered by the web server. In short, it provides each and every detail of the web server in a structured manner.

Syntax:

<definitions
  xmlns="http://schemas.xmlsoap.org/wsdl/"
  targetNamespace="Your_Target_Namespace"
  xmlns:tns="Your_Target_Namespace_Alias"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <!-- Define data types using <types> element here -->
  <!-- Define messages using <message> elements here -->
  <!-- Define port types using <portType> elements here -->
  <!-- Define bindings using <binding> elements here -->
  <!-- Define services using <service> elements here -->
</definitions>

Below I have given a detailed description of the above code and the attributes used in it:

Attributes:

  • name specifies the name of the definitions
  • targetNamespace (tns) defines a unique namespace for the WSDL document
  • xmlns defines the default XML namespace for the WSDL document.
  • defines a namespace alias (“tns”) for the targetNamespace.
  • xsd defines an alias for the XML Schema namespace.
  • soap defines an alias for the SOAP (Simple Object Access Protocol) namespace.

 

Sub-elements of <definitions> Element:

  • <types>: This element is used to define data types using XML Schema.
  • <message>: This element defines the format of the messages that the service can send or receive.
  • <portType>: The portType element defines the abstract interface of the web service.
  • <binding>: This element specifies how the mapping between the interface and protocol is done.
  • <service>: Service element provides information about where the web service is located.

Example: A WSDL document that describes a “Calculator” with a single “Add” operation.

XML




<definitions
    xmlns:tns="http://example.com/calculator"
    name="Calculator"
    targetNamespace="http://example.com/calculator">
    <types>
        <xsd:schema targetNamespace="http://example.com/calculator">
            <xsd:element name="AddRequest">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="num1" type="xsd:int"/>
                        <xsd:element name="num2" type="xsd:int"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <!-- Define other data types here if needed -->
        </xsd:schema>
    </types>
  
    <message name="AddRequestMessage">
        <part name="parameters" element="tns:AddRequest"/>
    </message>
    <message name="AddResponseMessage">
        <part name="parameters" element="tns:AddResponse"/>
    </message>
  
    <portType name="CalculatorPortType">
        <operation name="Add">
            <input message="tns:AddRequestMessage"/>
            <output message="tns:AddResponseMessage"/>
        </operation>
        <!-- Define other operations here if needed -->
    </portType>
  
    <binding name="CalculatorBinding" 
             type="tns:CalculatorPortType">
        <soap:binding style="document" 
                      transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="Add">
            <soap:operation soapAction="http://example.com/calculator/Add"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
        <!-- Define binding details for other operations here if needed -->
    </binding>
  
    <service name="Calculator">
        <port name="CalculatorPort" 
              binding="tns:CalculatorBinding">
            <soap:address location="http://example.com/calculator/service"/>
        </port>
    </service>
</definitions>


Need of <definitions> element:

  • Root Element: It is the root element of the WSDL document and binds the entire description of the services. Other WSDL elements are contained within it.
  • Target Namespace: It defines the target namespace for the web service.
  • Namespaces: It helps in defining and referencing namespaces which allows the integration of XML schemas.
  • Versioning: It includes versioning information and documentation.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads