基于 REST 的 Web 服务中的 SOAP 消息

发布于 2024-12-05 18:52:25 字数 487 浏览 0 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2024-12-12 18:52:26

我认为“基于 SOAP 的服务”是指 WS-I Basic Profile Web 服务。这种区别很重要,因为 SOAP 可以与 REST 以及 WS-I BP Web 服务一起使用。让我解释一下。

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

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

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

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

另一方面,如果您向更广泛的 Web 受众公开 Web 服务,我想说已经出现了远离 WSI-BP 并转向 RESTful 风格的趋势。由于 REST 仅假设客户端支持 HTTP,因此可以使其与尽可能广泛的受众进行互操作。 REST 还为您提供了 Web 本身的可扩展性,支持资源缓存等,这使得它比 WSI-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 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 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.

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文