What are XML Web Services?
Estimated study time: 14 minutes.
An XML web service is a way for applications running on different platforms to talk to each other over the internet, using XML as the common language for requests and responses.
The Core Idea
Two systems don't need to share a programming language, operating system, or database — as long as both can send and understand XML over standard web protocols like HTTP, they can exchange data.
Typical Building Blocks
- SOAP — a strict, XML-based messaging protocol for web services.
- WSDL — an XML document that describes what a web service offers and how to call it.
- REST (with XML) — a lighter approach where XML is exchanged over standard HTTP verbs.
- UDDI — a (largely historical) directory for discovering available web services.
A Simple Request/Response Flow
Client --request (XML)--> Web Service
Client <--response (XML)-- Web Service
Where They're Still Used
XML web services are common in banking, government, healthcare, and other enterprise systems where formal contracts, strict validation, and interoperability with older systems matter more than raw simplicity.
Inside a SOAP Request and Response
A SOAP message is an XML document with a fixed outer shape. The Envelope wraps everything, an optional Header carries extra information such as security tokens, and the Body holds the actual operation and its data. Here is a SOAP 1.1 request asking a stock service for a price:
POST /StockService HTTP/1.1
Host: api.example.com
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:GetPrice"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<GetPrice xmlns="urn:example:stock">
<Symbol>INFY</Symbol>
</GetPrice>
</soap:Body>
</soap:Envelope>
A successful reply follows the same envelope pattern, with a response element inside the body. When something goes wrong, the body contains a Fault element instead:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unknown stock symbol</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
A Client fault code means the request was wrong, while a Server fault code means the service failed while handling a valid request. SOAP 1.2 uses the media type application/soap+xml, a different envelope namespace and slightly different fault element names.
How a Client Uses a WSDL, Step by Step
The WSDL file acts as the contract between both sides. A WSDL 1.1 document is organised into sections that answer different questions:
| Section | Answers |
|---|---|
types | What do the data structures look like? (usually XML Schema) |
message | What goes in and out of each call? |
portType | Which operations exist? |
binding | Which protocol and message style are used? |
service | At which address does the service live? |
- The client developer obtains the WSDL from the provider.
- A tool reads it and generates client classes, so code can call
GetPrice("INFY")like a normal method. Java, .NET and many other platforms include such generators. - At runtime the generated code builds the XML envelope, sends it over HTTP and parses the reply back into objects.
- If the provider changes the contract, the client regenerates its classes from the new WSDL.
Testers often load the same WSDL into a tool such as SoapUI or Postman to create sample requests for every operation automatically.
SOAP or REST: Choosing the Right Style
| Consideration | SOAP | REST |
|---|---|---|
| Contract | Formal WSDL and schema | Often an OpenAPI description, not mandatory |
| Message format | Always XML | Usually JSON, XML possible |
| Standards for security and reliability | WS-Security and related specifications | HTTPS plus tokens such as OAuth |
| Best fit | Enterprise integrations with strict contracts | Web and mobile apps, public APIs |
Safety and quality checklist
- Always send XML web service traffic over HTTPS.
- Validate incoming messages against the schema before processing them.
- Configure XML parsers to disable DTDs and external entities, which protects against XML External Entity (XXE) attacks.
- Return clear faults to callers without exposing stack traces or internal details.