SOAP requires a lot of code to complete each task and adheres to an XML (Extensible Markup Language) structure for each message unlike REST that mostly uses HTTP and JSON.
Construction of a SOAP Message
- soap:Envelope - a root element in every SOAP message; the tag requires a namespace attribute and can optionally supply an encodingStyle attribute.
- soap:Header - an optional element used to pass information along the message path. SOAP-defined attributes on the header blocks (encodingStyle, mustUnderstand, relay) indicate how the header blocks are to be processed by the SOAP nodes.
- soap:Body - mandatory element that contains the bulk of the SOAP message intended for the ultimate recipient. Namespaces can be used to describe what data to expect within the body.
- soap:Fault - used within the soap:Body tag for error messages when a SOAP API call is not able to complete. There are many possible causes for an error, including inaccurate SOAP formatting, a processing error on the server, and mismatched data type.
An application sends a SOAP request to a server and the server then returns an XML-formatted document with the resulting data, e.g., prices, location, features. The generated data comes in a standardized machine-parsable format, so the requesting application can integrate it directly.
An example of how to request an XML
The SOAP way of communication between applications is independent of the types of operating systems, technologies, and programming languages which makes it suitable for use with any transport protocol.
In combination with HTTP post/response exchanges, SOAP passes through firewalls and proxies, easily adjusting itself to existing computing and communication infrastructures.
All the facilities of XML are available to SOAP, including easy internationalization and expansibility with XML Namespaces.
The roles of the interacting parties are fixed when HTTP is used as a transport protocol.
The SOAP protocol is verbose, XML parsing is slow, and there is no standardized interaction model. This leads to the dominance of services that use the HTTP protocol more directly, such as REST API.