SOAP

SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
Or more simply: SOAP is a protocol for accessing a Web Service. (Simple Object Access Protocol)    HTTP + XML = SOAP
  • a format for sending messages
  • SOAP allows you to get around firewalls
    • Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic.
SOAP is an XML.

A SOAP message is an ordinary XML document containing the following elements:
1. An Envelope tag (root tag):
Identifies the XML document as a SOAP message
2. A Head tag (optional)
Contains application-specific information (like authentication, payment, etc) about the SOAP message.
Must be the first child.
It's children must be namespace-qualified.
soap:mustUnderstand="1|0"
whether a header entry is mandatory or optional for the recipient to process.
soap:actor="uri" A SOAP message may travel from a sender to a receiver by passing different endpoints along the message path. This attribute is used to address the Header element to a specific endpoint.

3. A Body tag
Contains call and response information.
The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.  Immediate child elements of the SOAP Body element may be namespace-qualified.
4. A Fault tag (optional)
Contains errors and status information. can only appear once in a SOAP message.
 <faultcode> VersionMismatch: An invalid namespace for the SOAP Envelope element
MustUnderstand: A mustUnderstand was not understood
Client: The message was incorrectly formed or contained incorrect information
Server: There was a problem with the server so the message could not proceed
 <faultstring> Text description.
 <faultactor> Who caused the fault to happen
 <detail> Holds application specific error information related to the Body element    



Basic SOAP syntax
MUST be encoded using XML
MUST use the SOAP Envelope namespace
MUST use the SOAP Encoding namespace
must NOT contain a DTD reference
must NOT contain XML Processing Instructions

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Header>
<m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:mustUnderstand="1">
soap:actor="http://www.w3schools.com/appml/">
234

</m:Trans>
</soap:Header>
<soap:Body>
...
<soap:Fault>
  ...
</soap:Fault>
</soap:Body>
</soap:Envelope>

Sample SOAP request and response:
 <?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>
  <m:GetPrice xmlns:m="http://www.w3schools.com/prices">
    <m:Item>Apples</m:Item>
  </m:GetPrice>
</soap:Body>

</soap:Envelope>
 <?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>
  <m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
    <m:Price>1.90</m:Price>
  </m:GetPriceResponse>
</soap:Body>

</soap:Envelope>






HTTP + XML = SOAP

A SOAP request could be an HTTP POST or an HTTP GET request. The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.

Content-Type: MIMEType; charset=character-encoding

Example
POST /item HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 250 //number of bytes



A SOAP Example
 POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>
 <?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPriceResponse>
    <m:Price>34.5</m:Price>
  </m:GetStockPriceResponse>
</soap:Body>

</soap:Envelope>


Sample phone book query with SOAP via user id
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:body pb="http://www.acme.com/phonebook">
<pb:GetUserDetails>
<pb:UserID>12345</pb:UserID>
</pb:GetUserDetails>
</soap:Body>
</soap:Envelope>











Comments