Tuesday, January 26, 2010

SOAP vs REST



I have never been a part of long debates on Using SOAP vs REST but i have heard technocrats fighting over choosing the best suited services. Though I have never experimented over REST services but I could figure out the rational behind using different feelers for web services. At GrapeCity people are loud about REST services and  its like a new kid on the first floor of my office space.

SOAP

SOAP stands for Simple Object Access Protocol developed by Microsoft last century.
With WSDL and XML SOAP has become the best and most secure means of transfer of XML messages over the web. The structure of SOAP is like a postal message, It has an Envelope, Header and a Body.

For example: A normal SOAP message would look like

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Header>
     <!-- Header -->
 </env:Header>
<env:Body>
    <!-- Body -->
 </env:Body>
</env:Envelope>
 
Example of a Simple SOAP Message to fetch Stock Prices:

Request:

GET /StockPrice HTTP/1.1
Host: example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
   xmlns:s="http://www.example.org/stock-service">
   <env:Body>
     <s:GetStockQuote>
          <s:TickerSymbol>IBM</s:TickerSymbol>
     </s:GetStockQuote>
   </env:Body>
</env:Envelope>

 Response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
   xmlns:s="http://www.example.org/stock-service">
   <env:Body>
     <s:GetStockQuoteResponse>
          <s:StockPrice>45.25</s:StockPrice>
     </s:GetStockQuoteResponse>
   </env:Body>
</env:Envelope>
********************

REST

REST Services are used for Point to Point communication on the Web.
REST has four actions derived from HTTP (GET/POST/PUT/DELETE)
The web service message to fetch Stock Prices can be re written using REST

Request:

GET /StockPrice/IBM HTTP/1.1
Host: example.org
Accept: text/xml
Accept-Charset: utf-8

Response:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<s:Quote xmlns:s="http://example.org/stock-service">
     <s:TickerSymbol>IBM</s:TickerSymbol>
     <s:StockPrice>45.25</s:StockPrice>
</s:Quote>
********************

SOAP 
Pros:

  • Langauge, platform, and transport independent
  • Designed to handle distributed computing environments
  • Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors
  • Built-in error handling (faults)
  • Extensibility

Cons:

  • Conceptually more difficult, more "heavy-weight" than REST
  • More verbose
  • Harder to develop, requires tools


REST 
Pros:

  • Language and platform independent
  • Much simpler to develop than SOAP
  • Small learning curve, less reliance on tools
  • Concise, no need for additional messaging layer
  • Closer in design and philosophy to the Web

Cons:

  • Assumes a point-to-point communication model--not usable for distributed computing environment where message may go through one or more intermediaries
  • Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop ("roll your own")
  • Tied to the HTTP transport model

 
I found an interesting blog article on REST Services.
For more information http://www.xfront.com/REST-Web-Services.html




No comments:

Post a Comment