Tuesday, June 18, 2013

Web Services with SOAP and REST

Almost every problem in computer science can be solved by sending large amounts of XML across the network. These solutions are called Web services. Nobody has solved Pi to the Nth place yet this way, but experts insist it can be done!

One reason Web services are so popular is that many organizations allow traffic only on HTTP port 80 or HTTPS port 443, so protocols were developed to send and receive data over these ports. SOAP and REST are two common ways to encapsulate XML data.


SOAP (simple object access protocol) is an envelope protocol on top of a transport protocol for sending and receiving data. It can run over email using SMTP but usually runs over HTTP or HTTPS. The XML interchange formats are defined by a WSDL (Web services definition language), which is often generated by a toolkit from a high-level language.

SOAP was designed in 1988 by people working at Microsoft, among others, and remains critical for the .NET framework. Visual Studio .NET is Microsoft's toolkit for use with many languages including C#. Other toolkits include Axis and JAX-WS for Java, and gSOAP for C++.


REST (representational state transfer) is called a software architecture style, but it can be considered another protocol on top of HTTP or HTTPS for sending and receiving XML data. Simpler than SOAP, it uses only the get, put, post, patch, and delete methods. Sometimes REST sends JSON (JavaScript object notation) instead of XML.

REST was defined in a 2000 dissertation by Roy Fielding, and developed into a working system by a W3C group along with HTTP 1.1. Yahoo picked REST for many of their Web services.

Each REST interface assigned a URL, with GET and POST (or PUT) interfaces near each other. Generally POST modifies data, while PUT creates data. Programming languages can be mixed in a REST implementation. Java, Python, and Perl might be most frequently used.

The Chrome and Firefox browsers offer add-ons to examine a REST API, which can be very helpful during development.

REST versus SOAP

Many commentators prefer REST because it is simpler and lighter weight than SOAP, but SOAP has other advantages.

SOAP offers asynchronous processing, so it is suitable for long-running operations especially when reliability is a concern. SOAP requires a formal agreement between two sides (server and client) so stability by version is guaranteed.  SOAP also allows stateful context for functions that build on previous contexts

REST is a stateless, which has advantages for atomicity, consistency, and durability. REST makes good use of limited bandwidth and compute resources.


SOAP is a complicated and highly functional protocol that is heavily used in enterprise datacenters. REST is a simpler but highly functional protocol that is often preferred for agile development.

No comments:

Post a Comment