有人能用通俗易懂的英语解释一下什么是REST,什么是SOAP吗?Web服务是如何工作的?
当前回答
基于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服务的工作
其他回答
SOAP和REST都是指不同系统相互通信的方式。
REST使用的技术类似于浏览器与web服务器之间的通信:使用GET请求一个网页,在表单字段中发布,等等。
SOAP提供了类似的功能,但是通过来回发送XML块来完成所有工作。SOAP的另一个关键组件是WSDL,它是一种描述支持哪些函数和数据元素的XML文档。可以使用wsdl以编程方式“发现”支持哪些函数,以及生成编程代码存根。
关于SOAP和REST的简单解释
SOAP -“简单对象访问协议”
SOAP是一种在Internet上传输消息或少量信息的方法。SOAP消息是XML格式的,通常使用HTTP(超文本传输协议)发送。
休息-具象状态转移
Rest是一种在客户端和服务器之间发送和接收数据的简单方法,它没有定义很多标准。您可以以JSON、XML甚至纯文本的形式发送和接收数据。与SOAP相比,它是轻量级的。
SOAP -简单对象访问协议是一个协议!
具象状态传输是一种架构风格!
SOAP是一种用于传输消息的XML协议,通常通过HTTP传输
REST和SOAP可以说不是相互排斥的。基于rest的体系结构可能使用HTTP或SOAP或其他通信协议。REST针对web进行了优化,因此HTTP是一个完美的选择。HTTP也是Roy Fielding论文中讨论的唯一协议。
尽管REST和SOAP显然非常不同,但这个问题确实说明了REST和HTTP经常是串联使用的事实。这主要是由于HTTP的简单性及其与RESTful原则的非常自然的映射。
REST基本原则
客户端和服务器之间的通信
客户机-服务器体系结构具有非常明显的关注点分离。所有以RESTful风格构建的应用程序原则上也必须是客户机-服务器。
无状态的
每个客户端对服务器的请求都要求完全表示其状态。服务器必须能够在不使用任何服务器上下文或服务器会话状态的情况下完全理解客户端请求。因此,所有的状态都必须保存在客户机上。稍后我们将更详细地讨论无状态表示。
缓存
可以使用缓存约束,从而将响应数据标记为可缓存或不可缓存。任何标记为可缓存的数据都可以被重用作为对相同后续请求的响应。
统一的接口
All components must interact through a single uniform interface. Because all component interaction occurs via this interface, interaction with different services is very simple. The interface is the same! This also means that implementation changes can be made in isolation. Such changes, will not affect fundamental component interaction because the uniform interface is always unchanged. One disadvantage is that you are stuck with the interface. If an optimization could be provided to a specific service by changing the interface, you are out of luck as REST prohibits this. On the bright side, however, REST is optimized for the web, hence incredible popularity of REST over HTTP!
上述概念代表了REST的定义特征,并将REST体系结构与其他体系结构(如web服务)区分开来。值得注意的是,REST服务是web服务,但web服务不一定是REST服务。
请参阅关于REST设计原则的博客文章,了解更多关于REST和上述要点的详细信息。
这两种方法都被许多大型公司采用。这是个人喜好的问题。我更喜欢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是一种消息格式,用于断开连接的系统(如通过internet)交换信息/数据。它处理来回的XML消息。
Web服务传输或接收SOAP消息。它们的工作方式因所用语言不同而不同。
推荐文章
- 有没有REST api的命名规范指南?
- 什么是HTTP中的“406-不可接受的响应”?
- 哪些HTTP方法与哪些CRUD方法相匹配?
- 如何从iPhone访问SOAP服务
- RESTful服务中部分更新的最佳实践
- JAX-RS / Jersey如何自定义错误处理?
- 如何POST表单数据与Spring RestTemplate?
- Restful API服务
- 在用nodejs和express创建的REST API中设置响应状态和JSON内容的正确方法
- 如何POST JSON数据与PHP卷曲?
- REST身份验证方案的安全性
- 如何在package.json中使用“main”参数?
- 跨REST微服务的事务?
- 致命错误:未找到类“SoapClient”
- 调用webrequest, POST参数