Tutorial
Learn SOAP and XML
SOAP web services still run much of the world's banking, insurance, travel and government software, and XML turns up in REST APIs, feeds and standards everywhere. Both look intimidating at first: angle brackets, prefixes, URLs in attributes, a contract file hundreds of lines long. Each part turns out to be simple once someone explains what it's for.
These lessons start from XML itself and build up to a full test suite for a SOAP service. Every request was sent to the API at https://api.testingapis.com, which has real SOAP 1.1 and 1.2 services, a WSDL and XML endpoints, and every response shown is what came back. The code is Java, using only the JDK and JUnit, and every request is also shown with curl. If HTTP is new to you, start with the API testing tutorial. Some endpoints need a free account; set your key in TESTINGAPIS_KEY and the example project sends it with every request.
Download the example project
soap-xml-examples.zipA Maven project with 52 tests, one class per lesson. Java 21 and Maven 3.9 or later. Unzip and runmvn test.8 lessons3 levelsFree
Beginner
3 lessonsReading XML, what namespaces are for, and what a SOAP request and response look like on the wire.
- 01XML for API testersElements, attributes and text, the rules that make a document XML, and escaping.
- 02XML namespacesWhy names need namespaces, prefixes versus URIs, and the mistakes that make queries find nothing.
- 03What SOAP is, and a first callEnvelopes, operations and one URL for everything, in SOAP 1.1 and 1.2, with curl and Java.
Intermediate
3 lessonsThe WSDL contract, how SOAP reports errors, and XPath for finding values in any XML response.
- 04Reading a WSDLThe five parts of the contract a SOAP service publishes, and what tools do with it.
- 05SOAP faultsHow errors come back in each version, which side is to blame, and the status codes that go with them.
- 06XPath for testing XML responsesPaths, predicates, functions and attributes, with and without namespaces.
Advanced
2 lessonsA test suite for a SOAP service in Java, and REST APIs that send and receive XML.
Words you'll meet
14 termsEach one is explained properly in its lesson. This list is for looking one up later.
| Term | Meaning | Explained in |
|---|---|---|
| Element | A start tag, its content and an end tag: <name>Ana</name> | Lesson 1 |
| Attribute | A name and quoted value inside a start tag: id="1" | Lesson 1 |
| Well-formed | Following XML's own rules, so a parser can read the document at all | Lesson 1 |
| Namespace | A URI that says which vocabulary an element belongs to | Lesson 2 |
| Prefix | A short local nickname for a namespace URI, such as soap: | Lesson 2 |
| Envelope | The root element of every SOAP message, holding an optional Header and a Body | Lesson 3 |
| SOAPAction | The SOAP 1.1 header naming the operation being called | Lesson 3 |
| WSDL | The XML document in which a SOAP service describes its operations, messages and address | Lesson 4 |
| Binding | The part of a WSDL that says how to call the service: SOAP version, style, actions | Lesson 4 |
| Fault | SOAP's standard error element, with a code and a reason | Lesson 5 |
| XPath | A language for selecting parts of an XML document | Lesson 6 |
| Predicate | A condition in square brackets that filters an XPath step | Lesson 6 |
| XML Schema | A language for describing which elements, types and values a document may contain | Lesson 7 |
| Content negotiation | Choosing a response format with the Accept header | Lesson 8 |