XML WSDL

Web services description language (WSDL) is an XML-based file that tells the client app what the web service does. WSDL is written in XML so any programming language can read the file. It is the standard format for describing a web service. The WSDL language is used to specify how to communicate with XML-based services.

Structure of a WSDL Document

<definitions name="ServiceName" 
targetNamespace = "http://www.gfg.com/wsdl/GfgService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types> ...</types>
<message> ....</message>
<portType>... </portType>
<binding> ...</binding>
<service>...</service>
</definitions>

We are creating a client WSDL document that calculates Simple Interest

<message name="getSimpleInterestRequest">
<part name="Principle" type="xs:int"/>
<part name="RateOfInterest" type="xs:int"/>
<part name="Time" type="xs:int"/>
</message>
  • Similarly we have output message called getSimpleInterestResponse. It has one parameter whose name is SimpleInterest. Datatype of this parameter is int.
<message name="getSimpleInterestResponse">
<part name="SimpleInterest" type="xs:int"/>
</message>
  • Now we have portType. It is a container of different types of operation that end user are implementing. When user create WSDL, they need to provide the desirable list of operation that the system is supporting. In our example we are only supporting one operation getSimpleInterest. In the future updates if we have any requirement to calculate compound interest, then it will be added under this port operation.
<portType name="SimpleInterestCalculator">
<operation name="getSimpleInterest">
<input message="getSimpleInterestRequest"/>
<output message="getSimpleInterestResponse"/>
</operation>
</portType>
  • In the previous steps we have defined what would be the input and output message. We have defined what would be the name of operation. Now next step that comes into picture is we are binding all these operations. We use <binding></binding> to bind all these operations. We name this tag as SimpleInterestCalculator. In next part of code we are performing soap action for that particular operation. We use style=”document” , to specify what type of style that particular web service follow.
<binding type="Calculator" name="SimpleInterestCalculator">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation>
<soap:operation soapAction="http://gfg.com/getSimpleInterest"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>

Example: Here is the complete code

XML




<definitions name="CalculatorService"
   targetNamespace="http://www.examples.com/wsdl/CalculatorService.wsdl"
   xmlns="http://schemas.xmlsoap.org/wsdl/">
   <message name="getSimpleInterestRequest">
      <part name="Principle" type="xs:int"/>
      <part name="RateOfInterest" type="xs:int"/>
      <part name="Time" type="xs:int"/>
   </message>
   <message name="getSimpleInterestResponse">
      <part name="SimpleInterest" type="xs:int"/>
   </message>
   <portType name="SimpleInterestCalculator">
      <operation name="getSimpleInterest">
         <input message="getSimpleInterestRequest"/>
         <output message="getSimpleInterestResponse"/>
      </operation>
   </portType>
   <binding type="SimpleInterestCalculator" name="SimpleInterestCalculator">
      <soap:binding style="document"
         transport="http://schemas.xmlsoap.org/soap/http" />
      <operation>
         <soap:operation soapAction="http://example.com/getSimpleInterest"/>
         <input>
         <soap:body use="literal"/>
         </input>
         <output>
            <soap:body use="literal"/>
         </output>
      </operation>
   </binding>
</definitions>