简体   繁体   English

REST如何使用SOAP作为协议?

[英]How REST can use SOAP as protocol?

After reading lots of articles about web services, I got to know that REST can use SOAP as protocol. 在阅读了许多有关Web服务的文章之后,我知道REST可以使用SOAP作为协议。 But I am not getting that, in REST architectural style how and where SOAP can fit? 但是我没有得到,以REST架构风格,SOAP如何以及在哪里适合?

REST is an architectural style, which if applied correctly allows the decoupling of clients from servers, similar to web browsers which aren't coupled to any specific web server in particular but to the media types they exchange. REST是一种体系结构样式,如果正确应用,则可以使客户端与服务器解耦,这与Web浏览器类似,Web浏览器没有特别耦合到任何特定的Web服务器,但耦合到它们交换的媒体类型。 SOAP on the otherhand is a protocol that describes the syntax expected and its semantics in detail in a W3C recommendation which is usually said to couple clients to the implementation as the contract is usually pregenerated into stub-classes the actual client usually compiled against and interacting with. 另一方面,SOAP是一种协议,该协议在W3C建议中详细描述了预期的语法及其语义,该协议通常被称为将客户端耦合到实现,因为通常将合同预先生成为实际针对实际客户端编译并与之交互的存根类。 。 If the service interface is changing for some reasons older implementations will break with some certainty. 如果服务接口由于某些原因而发生变化,则较早的实现将肯定会中断。

While REST itself is not a protocol itself (it does not define any syntax of messages to be exchange nor their order) it does however require to use other protocols according to the rules outlines by the protocol's standard. 尽管REST本身不是协议本身(它没有定义要交换的消息的语法或顺序),但是它仍然需要根据协议标准概述的规则使用其他协议。 Most often REST APIs restrict themselfs to HTTP though. 多数情况下,REST API都会将其自身限制为HTTP。 According to Roy Fielding however an application following the RESTful guidelines should not depend on a single communication protocol but support multiple ones. 根据Roy Fielding的说法,遵循RESTful准则的应用程序不应依赖于单个通信协议,而应支持多个通信协议。 This can be HTTP, SMTP, (S)FTP and other protocols such as SOAP. 这可以是HTTP,SMTP,(S)FTP和其他协议,例如SOAP。

One of the main constraints REST imposes is, that APIs must be hypertext driven and support clients in their venture of interacting with the service. REST施加的主要限制之一是,API必须是超文本驱动的,并支持客户与服务进行交互的冒险。 This usually goes hand in hand with providing clients with further URIs to interact with and hence allow a client to take further actions to follow a certain goal. 这通常与向客户提供其他URI进行交互,从而允许客户采取进一步的行动来遵循某个目标。 The form of the URI isn't the important part (whether it contains a verb or not is not of relevance to a RESTful client) as a client should not analyze the URI itself and thus deduct certain semantics but instead use an accompanying relation name. URI的形式不是重要的部分(是否包含动词或与RESTful客户端无关),因为客户端不应该分析URI本身并因此推论某些语义,而应使用伴随的关系名称。 If the actual URI changes for whatever reason a RESTful client will still be able to interact with the API itself by utilizing the relation name rather than having to interpret the URI itself. 如果实际URI由于任何原因而发生更改,则RESTful客户端仍将能够通过利用关系名称与API本身进行交互,而不必解释URI本身。

In addition to that, the knowlege of what further actions a client can take are outlined by the media type both server and clients could aggree upon. 除此之外,服务器和客户端可以同意的媒体类型概述了客户端可以采取的进一步操作的知识。 The media type contains a set of processing instructions which tell the recipient on how to interpret received data. 媒体类型包含一组处理指令,这些指令告诉接收者如何解释接收到的数据。

A REST API response can thus contain a link to a SOAP endpoint which the client could invoke. REST API响应因此可以包含到客户端可以调用的SOAP端点的链接。 The content negotiation may tell the client that media type application/soap+xml is required which gives the client a clue that a SOAP 1.2 service is sitting at the URI location. 内容协商可以告诉客户端需要媒体类型application/soap+xml ,这为客户端提供了一个SOAP 1.2服务位于URI位置的线索。 As SOAP services are usually invoked via plain HTTP POST the invocation of the service method itself isn't the actual problem, it's how the client will know what to send and how to format it actually. 由于SOAP服务通常是通过纯HTTP POST调用的,因此服务方法本身的调用并不是真正的问题,这是客户端如何知道要发送的内容以及如何对其进行实际格式化的方式。

Although SOAP clients are often compiled against stub-classes which implement a certain contract expoxed via WSDL, the service itself may be invoked dynamically by interpreting the WSDL contract and mingling the necessary information together as well and thus send a well-formed SOAP message to the respective endpoint. 尽管SOAP客户端通常是根据存根类编译的,这些存根类实现了通过WSDL取消的某个特定合同,但是可以通过解释WSDL合同并将必要的信息混合在一起来动态调用服务本身,从而将格式正确的SOAP消息发送给各自的端点。 The problem I see here though is, that while the SOAP service endpoint as well as the method to invoke may be defined easily within an URI, the contract description (WSDL) may not necessarily be available by appending a ?wsdl to the end of that URI and thus the WSDL contract needs to be specified in some other way. 我在这里看到的问题是,虽然可以在URI中轻松定义SOAP服务端点以及调用的方法,但是通过在其末尾附加?wsdl可能不一定可以获得合同描述(WSDL)。 URI和WSDL约定需要以其他方式指定。

Neither HTML nor in JSON HAL define propper attributes in links to instruct clients to use certain WSDL contracts for generating a proper message content. HTMLJSON HAL均未在链接中定义适当的属性,以指示客户端使用某些WSDL合同来生成适当的消息内容。 Not sure if profile s can fill this spot actually. 不知道profile是否可以实际填补这个位置。 I'm also not aware that any other media type or protocol does at the moment. 我还不知道目前还有其他媒体类型或协议。 This would therefore require some kind of implicit (or as Fielding named it "out-of-band") information integrated into the client itself which increase the likelihood of failing in case someone publishes SOAP services or their contract differently as the client wont be able to lookup that WSDL any further. 因此,这将需要某种隐式(或Fielding称其为“带外”)信息集成到客户端本身,如果某人以不同的方式发布SOAP服务或其合同,则增加了失败的可能性进一步查找该WSDL。

In summary, while REST should be able to coop with SOAP in general, certain work has yet to be done in order to support clients in dynamically assembling the required information needed to issue valid requests to the service IMO. 总而言之,尽管REST通常应该能够与SOAP配合使用,但仍需要完成某些工作以支持客户端动态组合向服务IMO发出有效请求所需的必需信息。 When such support is available I don't see a major issue of sending SOAP messages via RESTful clients. 当提供这种支持时,我看不到通过RESTful客户端发送SOAP消息的主要问题。 Though, I haven't seen any real-world attempts to invoke SOAP from a (real) RESTful API (though they are actually sparse yet). 但是,我还没有看到任何实际尝试从(真实的)RESTful API调用SOAP的尝试(尽管实际上它们还很稀疏)。 Usually both are separated. 通常两者是分开的。 And while there have been attempts to describe REST services similar to SOAP (hint: WADL ) this approach was everything but RESTful. 尽管尝试过描述类似于SOAP的REST服务(提示: WADL ),但这种方法除了RESTful之外,什么都没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM