REST是更好的Web服务方法还是SOAP?或者它们是针对不同问题的不同工具?或者这是一个微妙的问题——也就是说,一个人在某些领域比另一个人稍微好一点,等等?
我尤其希望了解这些概念以及它们与php世界以及现代高端网络应用程序的关系。
REST是更好的Web服务方法还是SOAP?或者它们是针对不同问题的不同工具?或者这是一个微妙的问题——也就是说,一个人在某些领域比另一个人稍微好一点,等等?
我尤其希望了解这些概念以及它们与php世界以及现代高端网络应用程序的关系。
当前回答
REST是一个体系结构,SOAP是一个协议。
这是第一个问题。
您可以在REST应用程序中发送SOAP信封。
SOAP本身实际上是相当基本和简单的,它之上的WSS-*标准使它非常复杂。
如果您的消费者是其他应用程序和其他服务器,那么目前对SOAP协议有很多支持,在现代ide中移动数据的基本操作基本上就是单击鼠标。
如果您的消费者更有可能是ria或Ajax客户端,那么您可能希望使用比SOAP更简单、更适合客户端的东西(特别是JSON)。
通过HTTP发送的JSON包不一定是REST体系结构,它只是发送到url的消息。所有这些都是完全可行的,但是REST习惯用法有一些关键组件。然而,这两者很容易混淆。但是,仅仅因为您谈论的是HTTP请求,并不一定意味着您拥有REST体系结构。您可以有一个完全没有HTTP的REST应用程序(注意,这种情况很少见)。
因此,如果您的服务器和消费者对SOAP“满意”,SOAP和WSS堆栈就可以很好地为您服务。如果你在做一些特别的事情,想要更好地与web浏览器交互,那么一些轻量级的HTTP协议也可以很好地工作。
其他回答
请收听本期播客找出答案。如果你想在不听的情况下知道答案,那么好吧,这是REST。但我真的建议你听。
1.从我的经验来看。我想说REST让你可以选择访问已经构建好的URL。>一个词搜索谷歌。该URL可以用作REST的web服务。 在SOAP中,您可以创建自己的web服务并通过SOAP客户机访问它。
REST支持文本、JSON、XML格式。因此,两个应用程序之间的通信更加通用。而SOAP仅支持XML格式的消息通信。
SOAP目前具有更好的工具的优势,它们可以为服务层生成大量样板代码,也可以从任何给定的WSDL生成客户端。
REST更简单,因此更容易维护,位于Web体系结构的核心,允许更好的协议可见性,并且已被证明可以扩展到WWW本身的大小。有些框架可以帮助您构建REST服务,如Ruby on Rails,有些甚至可以帮助您编写客户端,如ADO。NET数据服务。但在大多数情况下,缺乏工具支持。
这是微妙的。
如果您需要让其他系统与您的服务进行接口,那么由于您使用契约、WSDL和SOAP标准所拥有的“验证”层,许多客户端将更乐于使用SOAP。
对于日常系统对系统的调用,我认为SOAP是很多不必要的开销,而简单的HTML调用就可以了。
快速了解一下2012年的问题:
REST在以下方面发挥了很好的作用:
Limited bandwidth and resources. Remember the return structure is really in any format (developer defined). Plus, any browser can be used because the REST approach uses the standard GET, PUT, POST, and DELETE verbs. Again, remember that REST can also use the XMLHttpRequest object that most modern browsers support today, which adds an extra bonus of AJAX. Totally stateless operations. If an operation needs to be continued, then REST is not the best approach and SOAP may fit it better. However, if you need stateless CRUD (Create, Read, Update, and Delete) operations, then REST is it. Caching situations. If the information can be cached because of the totally stateless operation of the REST approach, this is perfect.That covers a lot of solutions in the above three.
那么我为什么要考虑SOAP呢?同样,SOAP是相当成熟和定义良好的,并且带有完整的规范。REST方法就是这样一种方法,它对开发非常开放,所以如果你具备以下条件,那么SOAP就是一个很好的解决方案:
Asynchronous processing and invocation. If your application needs a guaranteed level of reliability and security then SOAP 1.2 offers additional standards to ensure this type of operation. Things like WSRM – WS-Reliable Messaging. Formal contracts. If both sides (provider and consumer) have to agree on the exchange format then SOAP 1.2 gives the rigid specifications for this type of interaction. Stateful operations. If the application needs contextual information and conversational state management then SOAP 1.2 has the additional specification in the WS* structure to support those things (Security, Transactions, Coordination, etc). Comparatively, the REST approach would make the developers build this custom plumbing.
http://www.infoq.com/articles/rest-soap-when-to-use-each