有人能用通俗易懂的英语解释一下什么是REST,什么是SOAP吗?Web服务是如何工作的?


当前回答

这两种方法都被许多大型公司采用。这是个人喜好的问题。我更喜欢REST,因为它更容易使用和理解。

简单对象访问协议(SOAP):

SOAP builds an XML protocol on top of HTTP or sometimes TCP/IP. SOAP describes functions, and types of data. SOAP is a successor of XML-RPC and is very similar, but describes a standard way to communicate. Several programming languages have native support for SOAP, you typically feed it a web service URL and you can call its web service functions without the need of specific code. Binary data that is sent must be encoded first into a format such as base64 encoded. Has several protocols and technologies relating to it: WSDL, XSDs, SOAP, WS-Addressing

具象状态转移(REST):

REST need not be over HTTP but most of my points below will have an HTTP bias. REST is very lightweight, it says wait a minute, we don't need all of this complexity that SOAP created. Typically uses normal HTTP methods instead of a big XML format describing everything. For example to obtain a resource you use HTTP GET, to put a resource on the server you use HTTP PUT. To delete a resource on the server you use HTTP DELETE. REST is a very simple in that it uses HTTP GET, POST and PUT methods to update resources on the server. REST typically is best used with Resource Oriented Architecture (ROA). In this mode of thinking everything is a resource, and you would operate on these resources. As long as your programming language has an HTTP library, and most do, you can consume a REST HTTP protocol very easily. Binary data or binary resources can simply be delivered upon their request.

在谷歌上有关于REST和SOAP的无休止的争论。

我最喜欢的是这个。 2013年11月27日更新:保罗·普莱斯科德的网站似乎已经下线,这篇文章不再可用,不过可以在Wayback Machine上找到副本,或者在CiteSeerX上以PDF格式找到。

其他回答

SOAP -“简单对象访问协议”

SOAP是一种在Internet上传输消息或少量信息的简单方法。SOAP消息是XML格式的,通常在发送时控制HTTP。

REST -“具象状态传输”

REST是风扇和服务器之间的可能性和接收信息的基本过程,它没有明确定义许多标准。您可以以JSON、XML甚至纯文本的形式发送和接受信息。与SOAP相比,它是轻量级的。

这是你能找到的最简单的解释。

这篇文章以丈夫对妻子的叙述为例,丈夫用纯外行的语言向妻子解释REST。一定要读!

如何向我的妻子解释休息(原始链接) 如何向妻子解释休息(2013-07-19工作链接)

REST是一种用于设计网络应用程序的体系结构风格。其思想是,使用简单的HTTP在机器之间进行调用,而不是使用复杂的机制(如CORBA、RPC或SOAP)来连接机器。

基于soap的Web服务 简而言之,基于soap的服务模型将世界视为一个由相互平等的对等点组成的生态系统,这些对等点不能相互控制,但必须通过遵守已发布的契约来共同工作。这是有效的 混乱的现实世界的模型,以及基于元数据的契约形成SOAP服务接口。

我们仍然可以将SOAP与基于xml的远程过程调用相关联,但是基于SOAP的Web服务技术已经成为一种灵活而强大的消息传递模型。

SOAP假定所有系统都是独立的,并且没有系统知道其他系统的内部信息和内部功能。 这样的系统最多能做的就是互相发送消息,并希望它们能被采取行动。系统发布它们承诺遵守的契约,而其他系统依赖这些契约与它们交换消息。

Contracts between systems are collectively called metadata, and comprise service descriptions, the message exchange patterns supported and the policies governing qualities of service (a service may need to be encrypted, reliably delivered, etc.) A service description, in turn, is a detailed specification of the data (message documents) that will be sent and received by the system. The documents are described using an XML description language like XML Schema Definition. As long as all systems honor their published contracts, they can inter operate, and changes to the internals of systems never affect any other. Every system is responsible for translating its own internal implementations to and from its contracts

REST -具象状态传输。物理 协议是HTTP。基本上,REST是指web上所有可以通过URL唯一识别的不同资源。可以在这些资源上执行的所有操作都可以用一组有限的动词(“CRUD”动词)来描述,这些动词又映射到HTTP动词。

REST的“重量级”比SOAP少得多。

web服务的工作

我将从第二个问题开始:什么是Web服务?原因显而易见。

WebServices本质上是公开某些功能或数据的逻辑片段(您可以模糊地将其称为方法)。客户端实现(技术上讲,消费是这个词)只需要知道方法将要接受的参数是什么,以及它将要返回的数据类型(如果它确实要返回的话)。

下面的链接以极其清晰的方式讲述了关于REST和SOAP的一切。

REST vs SOAP

如果您还想知道什么时候选择什么(REST或SOAP),那么更有理由经历它!