How to access SOAP services from iPhone
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
SOAP services are older than most modern iOS networking stacks, but they still show up in enterprise systems, payment gateways, and internal business APIs. Accessing them from an iPhone is completely possible, but you usually have to assemble the XML envelope yourself and handle the response as raw XML.
On iOS, the usual approach is to send an HTTP POST request with a SOAP envelope in the body, then parse the response with XMLParser. The hardest part is rarely networking itself; it is matching the exact XML structure and headers expected by the service.
Build the SOAP Request
Most SOAP endpoints expect:
- '
Content-Type: text/xml; charset=utf-8' - an optional
SOAPActionheader - an XML document containing the SOAP envelope and body
Here is a minimal Swift example using URLSession:
The endpoint URL, namespace, method name, and action header must match the service definition. If even one of those pieces is wrong, the server may return a fault or a plain HTTP error.
Parse the SOAP Response
SOAP responses are XML documents with wrapper elements around the data you actually want. A lightweight option on iOS is XMLParser.
This approach works well when you only need a few fields. If the service has complex nested objects, you may want a more structured XML mapping layer, but the underlying flow is still just HTTP plus XML parsing.
Use the WSDL as a Contract
Many SOAP services publish a WSDL file that describes available operations, namespaces, and message shapes. On iOS, you normally do not consume the WSDL directly at runtime the way some desktop frameworks do. Instead, you read it once, figure out the required XML and headers, and encode those in your app.
That is why SOAP integrations on iPhone projects feel more manual than REST integrations. There is no built-in high-level client generator in standard iOS APIs, so correctness depends on matching the contract exactly.
Handle Authentication and Faults
Some SOAP services use HTTP basic authentication, custom headers, or tokens inside the SOAP header section. Others return application errors as SOAP faults even when the HTTP status code is 200.
That means you should inspect both the transport layer and the XML body. A request can succeed at the HTTP level but still contain a fault element explaining that authentication failed or that the operation name was wrong.
Common Pitfalls
- Sending the right XML to the wrong namespace. SOAP servers are often strict about namespaces and action names.
- Forgetting the
SOAPActionheader when the service requires it. - Assuming the response payload is the first child element you see. SOAP wrappers and namespaces add extra structure.
- Treating a
200response as a guaranteed success. The real error may be inside a SOAP fault element. - Trying to call the WSDL URL as if it were the service endpoint. The WSDL describes the service; it is not usually the operation endpoint itself.
Summary
- iPhone apps can access SOAP services with
URLSessionand XML parsing. - Build a correct SOAP envelope and set the required HTTP headers.
- Parse the XML response carefully, including the SOAP wrapper elements.
- Use the WSDL to learn the contract, then encode that contract in Swift.
- Check for SOAP faults even when the HTTP request itself appears successful.

