views:

1029

answers:

5

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:

$user->setLastName('Jones');
$user->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.

+3  A: 

They are different models... REST is data-centric, where-as SOAP is operation-centric. i.e. with SOAP you tend to have discreet 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)

Marc Gravell
A: 

The key differences are basically tooling.

Many of the high end SOAP stacks shroud the vast bulk of the SOAP infrastructure from the developer, to where you are working pretty much solely with DTO's/Documents and RPC.

REST over HTTP puts more of that burden upon you the developer (negotiating formats [XML, JSON, HTTP POST], parsing results [DOM, maps, DTO marshalling, etc.]).

Obviously, you can write a layer of logic to make dealing with this detail easier. And some REST frameworks have arrived to make this easier, but at the moment, it's still a task on your TODO list when you wish to use or consume such services.

Will Hartung
A: 

My feedback is that if you want remote state, you are not talking about web services. I don't know about any contemporary model that deal with remote state. I think that if you need remote state you are on your own ( without religion to follow ). Just throw xml from here to there and don't mind the theory.

I have to add that remote state is evil. Avoid it if you can.

Igal Serban
A: 

Soap is just a set of agreed upon XML schemas blessed by a standards group. It's strength is that it was designed for interoperability and it supports many enterprise-class features. Soap on any platform will not provide the operations you are looking for. You need to design & implement the service contract to get those features.

Sounds like you want remote objects which neither Soap or REST are particularly good for. Maybe you'd be better off looking at XML-RPC.

Sixto Saez
A: 

I'm echoing what Marc Gravell mentioned. When people ask me about REST (and they usually have an idea about SOAP and SOA), I will tell them REST = ROA as it is resource/data oriented, it's a different paradigm and therefore has different design concerns.

For your case, if I'm reading you correctly, you want to avoid writing the wrapper code and need a solution that can store objects and their attributes remotely (and having them completely hidden from the developers). I can't really suggest a better solution.. Umm, let me know if either of these ever come close to meet your requirements:

  1. EJB3 / JPA
  2. CouchDB (REST/JSON)

Let me know too if I've interpreted your question wrongly.

If we compare XML-RPC and SOAP, the latter will give you better data types handling, for the former although you will be dealing with simpler data types but you will have to write a layer or adapter to convert them to your domain objects.

yc

yclian