SOAP API

SOAP is an XML-based messaging protocol specification for exchanging structured information over the Internet. It stands for Simple Object Access Protocol and strictly defines an entire method of communication.

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

SOAP request Live Request
GET /echo/get/soap HTTP/1.1
Host: reqbin.com
Accept: application/xml

SOAP response
HTTP/1.1 200 OK
Content-Type: application/xml

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" 
    soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
    <soap:Header>
        ...
    </soap:Header>

    <soap:Body>
        ...
        <soap:Fault>
            ...
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

Advantages


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.

Disadvantages


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.
Updated: Viewed: 5038 times