XML SOAP

SOAP stands for Simple Object Access Protocol. It is a messaging protocol that uses XML to format messages sent between web service clients and servers. SOAP defines a strict envelope structure for every message, making it reliable and formally defined — qualities that enterprise systems require.

SOAP Message Structure

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <soap:Header>
    <!-- Optional metadata: authentication, security, routing -->
    <auth:token xmlns:auth="http://auth.example.com">
      ABC123XYZ
    </auth:token>
  </soap:Header>

  <soap:Body>
    <!-- The actual request or response data goes here -->
    <GetProductRequest xmlns="http://shop.example.com/">
      <productId>P001</productId>
    </GetProductRequest>
  </soap:Body>

</soap:Envelope>

SOAP Envelope Parts

PartRequiredPurpose
EnvelopeYesThe root element — wraps everything
HeaderNoMetadata — authentication tokens, session IDs, routing info
BodyYesThe actual request data or response data
Fault (inside Body)NoError information when something goes wrong

SOAP Request and Response Example

SOAP Request — Get Currency Rate

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetRateRequest xmlns="http://currency.example.com/">
      <fromCurrency>USD</fromCurrency>
      <toCurrency>INR</toCurrency>
    </GetRateRequest>
  </soap:Body>
</soap:Envelope>

SOAP Response — Rate Returned

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetRateResponse xmlns="http://currency.example.com/">
      <rate>83.42</rate>
      <asOf>2024-03-15</asOf>
    </GetRateResponse>
  </soap:Body>
</soap:Envelope>

SOAP Fault — Error Response

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Invalid currency code: XYZ</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

Key Points to Remember

  • SOAP is a protocol that uses XML to structure messages between client and server.
  • Every SOAP message has an Envelope containing an optional Header and a required Body.
  • SOAP Fault inside the Body reports errors back to the client.
  • SOAP travels over HTTP, HTTPS, SMTP, or other transports.
  • WSDL describes SOAP service contracts; UDDI was used for service discovery.
  • SOAP is heavily used in banking, healthcare, and enterprise integration.

Leave a Comment

Your email address will not be published. Required fields are marked *