Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created March 21, 2012 19:20
Show Gist options
  • Save lamprosg/2151619 to your computer and use it in GitHub Desktop.
Save lamprosg/2151619 to your computer and use it in GitHub Desktop.
Tutorial - Example of a SOAP message (Web Services)
<!-- SOAP = Simple Object Access Protocol -->
<!-- SOAP is a simple XML-based protocol to let applications exchange information over HTTP -->
<!-- SOAP is a protocol for accessing a Web Service -->
<?xml version="1.0"?>
<!-- SOAP envelope element mandatory with the exact namespace as shown -->
<!-- The encodingStyle attribute is used to define the data types used in the document -->
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<!-- Header element is optional, contains application-specific information -->
<!-- SOAP defines three attributes in the default namespace: mustUnderstand, actor, and encodingStyle -->
<!-- mustUnderstand="1" = the receiver processing the Header must recognize the element or else it will fail -->
<!-- A SOAP message may travel from a sender to a receiver by passing different endpoints -->
<!-- However, not all parts of a SOAP message may be intended for the ultimate endpoint.. -->
<!-- ..but for one or more of the endpoints on the message path.-->
<!-- SOAP actor attribute is used to address the Header element to a specific endpoint -->
<!-- encodingStyle attribute is used to define the data types used in the document as mentioned above -->
<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 element contains the actual SOAP message -->
<!-- The example below requests the price of apples -->
<!-- m:GetPrice and the Item elements above are application-specific elements-->
<!-- They are not a part of the SOAP namespace -->
<soap:Body>
<m:GetPrice xmlns:m="http://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
<!-- The optional SOAP Fault element is used to indicate error messages -->
<!-- Fault sub elements and fault codes here: http://www.w3schools.com/soap/soap_fault.asp -->
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
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>
HTTP/1.1 200 OK
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:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment