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

时间:2022-01-03 09:52:16

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/

免责声明:我对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

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

1 个解决方案

#1


17  

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的服务”,我假设您的意思是WS-I Basic Profile Web服务。区别很重要,因为SOAP可以与REST以及WS-I BP Web服务一起使用。让我解释。

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.

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

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

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是一种模式,而不是标准,因此对于真正RESTful的含义存在很多争议。有一个名为Richardson成熟度模型的概念,它为REST理想提出了一系列步骤。通过与Richardson的模型进行比较,我们可以确切地了解REST实现的RESTful。 WS-I BP Web服务在这种规模上处于0级(即,根本不是非常RESTful,仅使用HTTP作为哑传输层)。

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.

我会说选择REST与WS-I Basic Profile Web服务 - 这取决于您的受众。如果您正在企业内部开发B2B类型接口,则更常见的是看到WSI-BP Web服务。因为存在底层标准,并且由于企业供应商(例如IBM,Oracle,SAP,Microsoft)的成熟支持以及特别是在.NET和Java中的框架支持水平,WSI-BP很有意义当您需要快速完成任务并希望客户端在企业环境中轻松连接时,交换的数据就是业务数据,可以很好地序列化为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.

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

#1


17  

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的服务”,我假设您的意思是WS-I Basic Profile Web服务。区别很重要,因为SOAP可以与REST以及WS-I BP Web服务一起使用。让我解释。

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.

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

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

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是一种模式,而不是标准,因此对于真正RESTful的含义存在很多争议。有一个名为Richardson成熟度模型的概念,它为REST理想提出了一系列步骤。通过与Richardson的模型进行比较,我们可以确切地了解REST实现的RESTful。 WS-I BP Web服务在这种规模上处于0级(即,根本不是非常RESTful,仅使用HTTP作为哑传输层)。

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.

我会说选择REST与WS-I Basic Profile Web服务 - 这取决于您的受众。如果您正在企业内部开发B2B类型接口,则更常见的是看到WSI-BP Web服务。因为存在底层标准,并且由于企业供应商(例如IBM,Oracle,SAP,Microsoft)的成熟支持以及特别是在.NET和Java中的框架支持水平,WSI-BP很有意义当您需要快速完成任务并希望客户端在企业环境中轻松连接时,交换的数据就是业务数据,可以很好地序列化为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.

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