In this lab, you'll learn how to consume an existing SOAP web service. You'll read a WSDL (Web Service Description Language) file to understand the API, and make a SOAP request using curl. This lab is practical and lightweight—no enterprise SOAP internals, just enough to use a real SOAP API.
- SOAP (Simple Object Access Protocol) is an older protocol for exchanging structured data over HTTP, often using XML.
- Unlike REST, SOAP uses XML envelopes and a strict contract defined by a WSDL.
- Many legacy systems and some public APIs still use SOAP.
- A WSDL (Web Service Description Language) file describes the available operations, input/output formats, and endpoint URLs for a SOAP service.
- Example public SOAP service: Calculator WSDL
- Open the WSDL URL in your browser. You'll see XML describing the service, operations (like Add, Subtract), and message formats.
Note: This lab uses a public SOAP service for demonstration. If the service is unavailable, your instructor may provide a local SOAP example or pre-recorded response for inspection.
- SOAP requests are sent as XML in the body of an HTTP POST.
- The WSDL tells you the endpoint and the XML structure for each operation.
- Example: To call the
Addoperation on the Calculator service, the SOAP body looks like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>2</intA>
<intB>3</intB>
</Add>
</soap:Body>
</soap:Envelope>- Use curl to POST the SOAP XML to the service endpoint.
- Set the
Content-Type: text/xmlheader and theSOAPActionheader (from the WSDL).
curl -s \
-X POST \
-H "Content-Type: text/xml; charset=utf-8" \
-H "SOAPAction: \"http://tempuri.org/Add\"" \
--data @add.xml \
http://www.dneonline.com/calculator.asmx- Save your SOAP XML to a file called
add.xml. - The response will be XML containing the result.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddResponse xmlns="http://tempuri.org">
<AddResult>5</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope>Notice how SOAP requires a fixed XML structure and explicit operation names, while REST typically relies on HTTP verbs and simpler JSON payloads.
- Open the Calculator WSDL and review the operations.
- Write a SOAP XML request for the
Addoperation (as above) and save it asadd.xml. - Use the curl command to send the request and view the response.
- Try changing the numbers or calling a different operation (like
Subtract).
- SOAP is XML-based and uses a WSDL for contract.
- You can consume SOAP APIs with curl by sending XML POST requests.
- No need to learn enterprise SOAP internals for basic consumption!
below you can see the SOAP definition that specifies how to use the Add function.
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="Add">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="intA" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="intB" type="s:int"/>
</s:sequence>
</s:complexType>
</s:element>
...