基于 REST 的 Web 服务中的 SOAP 消息 [英] SOAP messages in REST based web service

查看:58
本文介绍了基于 REST 的 Web 服务中的 SOAP 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:我真的很困惑基于 REST 和基于 SOAP 的服务.
在阅读了基于 REST 的 Web 服务的许多教程(似乎彼此矛盾)之后,我想知道我们是否可以/应该使用 SOAP 在基于 REST 的 Web 服务中发送/接收消息?
我尝试了以下链接
1) http://www.ibm.com/developerworks/webservices/library/ws-restful/

Disclaimer: I am really confused between REST and SOAP based services.
After reading many tutorials (which seems contradictory to each other) on REST based web service I was wondering whether we can/should use SOAP to send/receive messages in REST based web service ?
I tried following links
1) http://www.ibm.com/developerworks/webservices/library/ws-restful/

2) http://rest.elkstein.org/2008/02/how-simple-is-rest.html

推荐答案

我认为基于 SOAP 的服务"指的是 WS-I 基本概要 Web 服务.区别很重要,因为 SOAP 可以与 REST 以及 WS-I BP Web 服务一起使用.让我解释一下.

By "SOAP based services" I assume you are meaning WS-I Basic Profile web services. The distinction is important because SOAP can be used with REST as well as WS-I BP web services. Let me explain.

SOAP 是一种基于 XML 的消息传递格式,用于交换数据.Soap 还定义了一种进行远程过程调用的方法.SOAP 是来自 W3C 的开放标准.SOAP 不知道底层传输层.HTTP 经常被用作传输层,但它可以愉快地运行在 SMTP 和 TCP 以及其他传输层上.

SOAP is an XML based messaging format for exchange of data. Soap also defines a means for making remote procedure calls. SOAP is an open standard from the W3C. SOAP is agnostic about the underlying transport layer. Frequently HTTP is used as a transport layer, but it can happily run over SMTP and TCP, and other transports too.

REST 是一种架构风格(不是标准),所以注意不要比较 REST和 SOAP 直接,因为你没有比较苹果和苹果.REST 采用 HTTP 并以它本来应该使用的方式使用它,以及它的所有微妙之处和丰富之处.REST 架构风格可用于传输任何格式的数据——它不强制要求任何特定的数据格式.因此 SOAP 是 REST 风格的 Web 服务的完美序列化格式.但是很多人在 REST 中使用 JSON、XML、纯文本和许多其他格式.您也可以通过 REST 愉快地交换二进制数据,例如图像文件.好处是您可以选择最适合您的应用程序的数据格式.

REST is an architectural style (not a standard), so be careful not to compare REST and SOAP directly because you are not comparing apples with apples. REST takes HTTP and uses it is the way it was meant to be used, with all its subtleties and richness. The REST architectural style can used to transfer data in any format - it does not mandate any particular data format. So SOAP is a perfectly good serialization format for a REST style web service. But many people use JSON, XML, plain text and many other formats with REST. You can happily exchange binary data over REST too, like image files. The nice thing is you get to choose the data format that makes most sense for your application.

请注意,由于 REST 是一种模式,而不是标准,因此对于真正的 RESTful 意味着什么存在很多争论.有一个称为 Richardson Maturity Model 的概念,它列出了实现 REST 理想的一系列步骤.通过与 Richardson 的模型进行比较,我们可以确切地看到特定 REST 实现的 RESTful 程度.WS-I BP Web 服务在这种规模上处于 0 级(即,根本不是 RESTful,只是使用 HTTP 作为一个愚蠢的传输层).

Note that since REST is a pattern, not a standard, there is a lot of debate about what it means to be truely RESTful. There is a concept called the Richardson Maturity Model which lays out a series of steps towards the REST ideal. By comparing with Richardson's model we can see exactly how RESTful a particular REST implementation is. WS-I BP web services are at Level 0 on this scale (ie. not very RESTful at all, just using HTTP as a dumb transport layer).

关于选择 REST 与 WS-I Basic Profile 网络服务,我会这样说 -这取决于你的观众.如果您正在企业内开发 B2B 类型的接口,则更常见的是看到 WSI-BP Web 服务.因为有一个底层标准,而且由于企业供应商(如 IBM、Oracle、SAP、Microsoft)的成熟支持,以及特别是在 .NET 和 Java 中的框架支持水平,WSI-BP 很有意义当您需要让某事快速进行,并且希望让客户能够轻松地在企业环境中进行连接,并且正在交换的数据是可以像 SOAP 一样很好地序列化的业务数据时.

I would say this about choosing REST vs WS-I Basic Profile web services - it depends on your audience. If you are developing a B2B type interface within an enterprise, it is more common to see WSI-BP web services. Because there is an underlying standard, and because of the mature support by enterprise vendors (such as IBM, Oracle, SAP, Microsoft) and because of the level of framework support particularly in .NET and Java, WSI-BP makes a lot of sense when you need to get something going quickly and you want to make it easy for clients to connect in an enterprise environment, and the data being exchanged is business data that serializes nicely as SOAP.

另一方面,如果您要向更广泛的 Web 受众展示 Web 服务,我会说有一种趋势是从 WSI-BP 转向 RESTful 风格.由于 REST 仅假设客户端支持 HTTP,因此可以使其与尽可能广泛的受众进行互操作.REST 还为您提供 Web 本身的可扩展性,支持资源缓存等,这使得它比 WSI-BP Web 服务更好地扩展到大量受众.

On the other hand if you are exposing web services to the wider web audience, I would say there has been a trend away from WSI-BP and towards the RESTful style. Because REST only assumes the client supports HTTP, it can be made to interoperate with the widest possible audience. REST also gives you the scalability of the web itself, with the support for caching of resources etc which makes it will scale up to a large audience much better than WSI-BP web services.

这篇关于基于 REST 的 Web 服务中的 SOAP 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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