tags:

views:

795

answers:

8

I am trying to make a decision whether I should use a REST service or a SOAP service for some web facing functions that I am producing. This decision is based on whether I can easily use the REST service in implementation. I would prefer to use REST, though I don't want to spend days coding the object model in PHP.

The services are being developed in .NET but will be consumed mainly by PHP.

Basically it has come down to one point: Ease of integration. Using SOAP in PHP I can use the NuSOAP library, which will generate the object model.

However with REST I cannot seem to find a way to easily generate that model, if this is possible I would use REST services as they are easier to document and extend, and also have the JSON abilities as well.

Can I generate an object model in PHP from an XML file/schema that I could then serialize with the REST service?

A: 

I had some trouble getting SOAP to work between diffent languages (PHP <> JAVA and PHP <> .NET)

If your going with SOAP, you might want to check out WS-I (Web Services Interoperability)

Bob Fanger
A: 

Based on your described requirements you should stick in the SOAP world. Remember, REST is just a style of architecting a distributed interface. It says nothing about how the functionality of that interface is implemented. There certainly is no need for mapping schemas to objects.

Having said that, if you look at the client tools in the WCF REST Starter kit you will find functionality to paste XML as a CLR type. This will do a best guess at creating a serializable class based on an XML instance document.

Also, from what you are describing ADO.NET Data Services would provide you a quick way of exposing RESTful data services to your PHP site.

....

Here is a question for you? If the .Net services are going to be consumed by a PHP site then why would you describe the .Net services as "web facing". From your description, these services sound more like a private implementation detail of your web site.

Darrel Miller
The reason is this, if they were simply internal services the answer is simple, use SOAP, because we would also use .NET to consume them internally. However because it is external and may also need to be consumed by other devices (mobiles, iphones etc) as well as other web pages (mine and others).
Bluephlame
A: 

If I were you I would:

  • investigate if NuSOAP tools can be used on just XSD. In the .NET world, you have svcutil (or in the ASMX days, wsdl.exe) to digest .wsdl files to produce proxy classes. But if you have only .xsd files, you can use the xsd.exe tool, or the "aftermarket" XsdObjectGen, which is like a supercharged xsd.exe. Are there similar tools in NuSOAP to do the same? Maybe this is obvious and you've already done it.
  • if that doesn't pan out, produce a dummy WSDL, and stuff the XSD you have into it. Then, process the .wsdl file with the NuSOAP tools. Grab the generated code, and remove the soap envelope and communications stuff, but retain the object serialization stuff. Not sure if this is possible, the way the PHP (or is it C?) code is generated by the NuSOAP tools. In .NET, it's easy to break the different pieces out.
Cheeso
A: 

The whole idea behind rest is that you do not use it with hackish "object models" like with SOAP. The problem is you're trying to use the system wrong :)

If you want object models, use SOAP.

If you want web-friendly APIs, use REST.

singpolyma
Is there is no compromise in the middle? really i want a web friendly REST API, with an easy to use implementation of the object Model. Perhaps i am missing something, as i know PHP is not strongly typed like .NET, which is were i have spent most of my time.
Bluephlame
A: 

For ease of integration, I'd go with a REST API. Since there is such a strong convention, integrating should be relatively straightforward for anybody's who's worked with REST before.

Ian Silber
A: 

So i think this could be something that i am looking for. but i would like to know if there is some sort of automation system out there for it

found it at http://devzone.zend.com/article/1713#Heading11

Extending Classes

While the above examples were all doable with PHP 4 and the domxml extension (only the API was a little bit different), the ability to extend DOM classes with your own code is a new feature of PHP 5. This makes it possible to write more readable code. Here's the whole example again, re-written to use the DomDocument class:

 class Articles extends DomDocument {
     function __construct() {
         //has to be called!
         parent::__construct();
     }

     function addArticle($title) {
         $item = $this->createElement("item");
         $titlespace = $this->createElement("title");
         $titletext = $this->createTextNode($title);
         $titlespace->appendChild($titletext);
         $item->appendChild($titlespace);
         $this->documentElement->appendChild($item);
     } } $dom = new Articles(); $dom->load("articles.xml");
 $dom->addArticle("XML in PHP5"); print
 $dom->save("newfile.xml");
Bluephlame
+5  A: 

You might not even have to go the class route. Simply ingest the data using simplexml and then traverse it as if it were an object. Or if you have json, json_decode($data, TRUE) would do the same thing (without attributes in brackets).

$ch = curl_init("http://example.com/some/rest/endpoint");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);

$obj = simplexml_load_string($data);
print $obj->some->data->you['need'];

That would print here if your XML was something like

<_>
 <some>
  <data>
   <you need="here" />
  </data>
 </some>
</_>
Paul Tarjan
SimpleXML automatically generates objects from your XML strings, I would highly suggest this route.
jakemcgraw
A: 

Hello !

I think this is exactly what you are looking for.

http://www.slideshare.net/matthieua/easy-rest-service-using-php-reflection-api-presentation

SleepyCod