Edward Tanguay Edward Tanguay - 10 months ago 51
Java Question

How do RESTful and SOAP Web Services differ in practice?

I am implementing web services for a PHP application and am trying to understand what both standard web services and RESTful web services have to offer.
My intent is to write wrapper code to abstract away the web service details so that developers can just "instantiate remote objects" and use them.
Here are my thoughts, perhaps some of you could add your experience and expand this:

RESTful Web Servcies

are basically just "XML feeds on demand", so e.g. you could write wrapper code for a client application so it could query the server application in this way:

$users = Users::getUsers("state = 'CO'");

  • this would in turn get an XML feed form a remote URL

  • $users could be made into a collection of full User objects, or

  • left as XML, or

  • turned into an array, etc.

  • the query script ("state = 'CO'") would be translated into SQL on the server side

  • RESTful Web Services are in general read-only from the view of the client, although you could write code which could use POST or GET to make changes on the server, e.g. passing an encrypted token for security, e.g.:

    $users = Users::addUser($encryptedTrustToken, 'jim',$encryptedPassword, 'James', 'Taylor');

and this would create a new user on the server application.

Standard Web Services

Standard Web Servcies in the end basically do the same thing. The one advantage they have is that client can discover their details via WSDL. But other than that, if I want to write wrapper code which allows a developer to instantiate, edit and save objects remotely, I still need to implement the wrapper code. SOAP doesn't do any of that for me, it can do this:

$soap = new nusoap_client('http://localhost/test/webservice_user.php?wsdl', true);
$user = $soap->getProxy();
$lastName = $user->lastName();

but if I want to edit and save:


then I need to e.g. handle all of the state on the server side, SOAP doesn't seem to hold that object on the server side for each client.

Perhaps there are limitations in the PHP SOAP implementation I am using (nusoap). Perhaps Java and .NET implementations do much more.

Will enjoy hearing your feedback to clear up some of these clouds.

Answer Source

They are different models... REST is data-centric, where-as SOAP is operation-centric. i.e. with SOAP you tend to have discrete operations "SubmitOrder", etc; but with REST you are typically a lot more fluid about how you are querying the data.

SOAP also tends to be associated with a lot more complexity (which is sometimes necessary) - REST is back to POX etc, and YAGNI.

In terms of .NET, tools like "wsdl.exe" will give you a full client-side proxy library to represent a SOAP service (or "svcutil.exe" for a WCF service):

var someResult = proxy.SubmitOrder(...);

For REST with .NET, I guess ADO.NET Data Services is the most obvious player. Here, the tooling (datasvcutil.exe) will give you a full client-side data-context with LINQ support. LINQ is .NET's relatively new way of forming complex queries. So something like (with strong/static type checking and intellisense):

var qry = from user in ctx.Users
          where user.State == 'CO'
          select user;

(this will be translated to/from the appropriate REST syntax for ADO.NET Data Services)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download