如何基于REST和SOAP的Web服务在实践中有什么不同? [英] How do RESTful and SOAP Web Services differ in practice?

查看:187
本文介绍了如何基于REST和SOAP的Web服务在实践中有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现Web服务的PHP应用程序,我试图了解这两个标准的Web服务和RESTful Web服务所提供的。 我的目的是写包装code抽象出来的​​Web服务细节,使开发人员可以只是实例化远程对象,并使用它们。 这里有我的想法,也许你们中的一些可以增加你的经验和扩大这样的:

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:

基于REST的Web Servcies

基本上只是XML提要点播,所以如您可以编写包装code的客户端应用程序,以便它可以查询这样的服务器应用程序:

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'");

  • 这将反过来又得到一个XML饲料形成一个远程URL
  • 在$用户可以制作成完整的用户对象的集合,或者
  • 在左为XML,或
  • 变成一个数组,等等。
  • 查询脚本(状态='有限公司')将被转换成SQL服务器端
  • REST Web服务在一般只读从客户端的角度,虽然你可以写code可能使用POST或GET,使服务器上,例如更改通过一个加密令牌的安全性,例如:

    • 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.:

      $用户=用户:: ADDUSER($ encryptedTrustToken,吉姆,$ encryptedPassword,'詹姆斯','泰勒');

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

      和这将创建服务器应用程序的新用户。

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

      标准的Web服务

      标准的Web Servcies到底基本上做同样的事情。一个优势,他们拥有的是该客户端可以通过WSDL发现他们的细节。但除此之外,如果我想写包装code,它允许开发人员能够远程实例,编辑和保存对象,我还需要实现包装code。 SOAP没有做任何的,对我来说,它可以这样做:

      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();
      

      那么我就需要如处理所有在服务器端的状态,SOAP似乎并没有持有该对象上为每个客户端服务器端。

      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.

      也许还有我使用(的NuSOAP)在PHP的SOAP实现的限制。也许Java和.NET实现做更多事情。

      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.

      推荐答案

      他们是不同的模式... REST是数据中心,其中,作为SOAP是操作中心。即使用SOAP,你往往有谨慎操作SubmitOrder等;但与REST你通常如何要查询的数据有更多的流体。

      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也往往与很多更复杂(这有时是必要的)相关 - REST是回到POX等,YAGNI

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


      在.NET方面,如Wsdl.exe用的工具会给你一个完整的客户端代理库,重新present SOAP服务(或svcutil.exe的一个WCF服务):

      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(...);
      

      有关REST与.NET,我想ADO.NET数据服务是最明显的球员。在这里,工具(datasvcutil.exe)会给你一个完整的客户端数据上下文使用LINQ的支持。 LINQ是.NET的相对较新形成复杂的查询方式。因此,像(与强/静态类型检查和智能感知):

      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;
      

      (这将被转换为/从对ADO.NET数据服务适当休息语法)

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

      这篇关于如何基于REST和SOAP的Web服务在实践中有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆