SOAP - WSDL

 

What is WSDL?

  • WSDL (Web Services Description Language) is an XML-based contract that describes what a SOAP service does and how to call it.

  • Think of it like an instruction manual for the web service: it tells the client what methods are available, what inputs are required, and what the outputs will look like.


Key Features of WSDL

  1. Describes Operations

    • Lists the functions (methods) the service provides.

    • Example: GetCustomer, AddOrder, SayHello.

  2. Defines Parameters

    • Specifies input and output message formats (data types, structure, order).

  3. Specifies Endpoints

    • Tells the client where (URL) the service is located.

  4. Machine-Readable

    • Tools (like Visual Studio, SoapUI, or Postman) can automatically generate proxy classes from WSDL so developers don’t have to handcraft XML.


Basic Structure of WSDL

A WSDL has these main sections:

  1. Types – Defines data types used (usually via XML Schema).

  2. Messages – Defines input and output messages.

  3. PortType – Defines operations (like an interface in C#).

  4. Binding – Defines how operations are transmitted (SOAP 1.1/1.2, HTTP, etc.).

  5. Service – Defines the service endpoint (the actual URL).


Example WSDL Snippet

<definitions name="HelloService"
             targetNamespace="http://example.com/hello"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="http://example.com/hello"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns="http://schemas.xmlsoap.org/wsdl/">

  <!-- Input/Output Messages -->
  <message name="SayHelloRequest">
    <part name="name" type="xsd:string"/>
  </message>
  <message name="SayHelloResponse">
    <part name="greeting" type="xsd:string"/>
  </message>

  <!-- Operations -->
  <portType name="HelloPortType">
    <operation name="SayHello">
      <input message="tns:SayHelloRequest"/>
      <output message="tns:SayHelloResponse"/>
    </operation>
  </portType>

  <!-- Binding (SOAP over HTTP) -->
  <binding name="HelloBinding" type="tns:HelloPortType">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="SayHello">
      <soap:operation soapAction="http://example.com/hello/SayHello"/>
      <input><soap:body use="literal"/></input>
      <output><soap:body use="literal"/></output>
    </operation>
  </binding>

  <!-- Service Endpoint -->
  <service name="HelloService">
    <port name="HelloPort" binding="tns:HelloBinding">
      <soap:address location="http://example.com/hello.asmx"/>
    </port>
  </service>
</definitions>

In C#

  • You point Visual Studio to the WSDL URL.

  • It auto-generates a proxy class so you can call:

var client = new HelloServiceClient();
string response = client.SayHello("John");

(no need to deal with raw XML).


 In short:
WSDL is the blueprint of a SOAP service — it defines what’s available, what data is expected, and how to reach the service.