Você está na página 1de 13

SOAP

Simple XML based protocol


Lets information exchange over HTTP
Platform and Language independent
Completely XML based

SOAP
SOAP - "Simple Object Access Protocol" .
Why?
WS expose useful functionality to Web users through a
standard Web protocol called SOAP.
What?
Simple markup language for describing messages between
applications.
How it works?
Uses mainly HTTP as a transport protocol. That is, HTTP
message contains a SOAP message as its payload section.
SOAP Characteristics
SOAP has three major characteristics:
Extensibility security and WS-routing are among
the extensions under development.
Neutrality - SOAP can be used over any transport
protocol such as HTTP, SMTP or even TCP.
Independent - SOAP allows for any programming
model .
SOAP Message?
Simple XML document
Has a fixed structure with the following,
An Envelope Element
Header Element
Body Element
Fault Element
What are they why are these needed?
Let us understand with an example
SOAP Elements
Consider a postal letter it has,
Envelope
Stamp
Address (From and To)
Return to
These tell how the letter will be received and
what to do in case of any failure.
Similarly
A SOAP message has a fixed structure
Envelope identifies that this XML doc is a SOAP
message has name space and encoding details
Header has header info like content type ,
character set (UTF- 8), etc
Body has call and response info
Fault errors and statuses

SOAP Request
POST /InStock HTTP/1.1
Host: www.stock.org
Content-Type: application/soap+xml; charset=utf-8 Content-Length: 150

<?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.stock.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
Some Rules
Header if specified must be the first child element
Name space always points to W3Cs soap
envelope name space link
Soap messgaes use some attributes like
MustUnderstand
(0/1) tells if header entry is mandatory
Actor
Tells about an end point using a URI
Encoding
defines data types
SOAP Response
HTTP/1.1 200 OK
Content-Type: application/soap; charset=utf-8
Content-Length: 126

<?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.stock.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
Fault element in SOAP can be of different
types like,
<faultcode> - code for identifying a fault
<faultstring> - explanation of the fault
<faultactor> - information on cause
<detail> - application specific error message
Fault codes some examples,
VersionMissMatch, Client, Server, MustUnderstand
SOAP HTTP Binding
HTTP communication
happens as below,
Client sends request and
gets response from
server
There are various HTTP
codes like 200, 400, etc
SOAP requests can travel
through HTTP in the
same way.

Client Server
To Sum up!
HTTP + XML = SOAP
Gives platform and language independency
Is itself a simple XML document with a fixed
strucutre
Has header, body and fault elements with
different attributes
Uses HTTP as transport protocol

Você também pode gostar