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
-
Describes Operations
-
Lists the functions (methods) the service provides.
-
Example:
GetCustomer
,AddOrder
,SayHello
.
-
-
Defines Parameters
-
Specifies input and output message formats (data types, structure, order).
-
-
Specifies Endpoints
-
Tells the client where (URL) the service is located.
-
-
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:
-
Types – Defines data types used (usually via XML Schema).
-
Messages – Defines input and output messages.
-
PortType – Defines operations (like an interface in C#).
-
Binding – Defines how operations are transmitted (SOAP 1.1/1.2, HTTP, etc.).
-
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.