SOAP Messaging

A SOAP message is an Envelope with an optional Header (security tokens and other WS-* extensions) and a Body holding the payload or a Fault. SOAP 1.1 (2000) and SOAP 1.2 (W3C Recommendation, Second Edition 27 April 2007) differ mainly in namespace and fault format. Every call is an HTTP POST to one URL; faults return with status 500:

soap_client.py: calling the service through its WSDL with zeepPython
from lxml import etree
from zeep import Client
from zeep.exceptions import Fault
from zeep.plugins import HistoryPlugin
import server
srv = server.start()                       # the service runs in this process, on port 31081
history = HistoryPlugin()
client = Client("booknest.wsdl", plugins=[history])    # the contract, read locally
op = client.service._binding._operations["GetPrice"]
print("from the WSDL:", op.name, op.input.signature(), "->", op.output.signature())
result = client.service.GetPrice(sku="BN-0003")
print("result:", result.price, result.inStock, type(result.price).__name__)
print(etree.tostring(history.last_sent["envelope"], pretty_print=True).decode().strip())
try:
    client.service.GetPrice(sku="BN-9999")
except Fault as f:
    print("Fault:", f.code, f.message)
srv.shutdown()
Output
from the WSDL: GetPrice sku: xsd:string -> price: xsd:decimal, inStock: xsd:boolean
result: 24.00 False Decimal
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:GetPrice xmlns:ns0="urn:booknest:pricing">
      <ns0:sku>BN-0003</ns0:sku>
    </ns0:GetPrice>
  </soap-env:Body>
</soap-env:Envelope>
Fault: s:Client Unknown SKU BN-9999

The signature and types came from the WSDL alone; zeep built the envelope, returned a Decimal and a bool, and raised the fault as an exception.


SOAP

Simple Object Access Protocol (SOAP) is used to exchange structured information in web services.

A SOAP message is an XML document consisting of an Envelope root element, which contains an optional Header and a mandatory Body:
ch10-soap-envelope.xmlXML
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
  </soap:Header>
  <soap:Body>
    <m:GetPrice xmlns:m="http://www.example.org/stock">
      <m:StockName>Google</m:StockName>
    </m:GetPrice>
  </soap:Body>
</soap:Envelope>