为什么比 SOAP 更喜欢 REST? [英] Why prefer REST over SOAP?
问题描述
如果我需要一个 Web 服务来回传递一个复杂的对象,我是否有理由更喜欢 SOAP 而不是 REST?以下是可能的 SOAP 消息示例:
If I need a web service to pass back and forth a complex object, is there a reason I should prefer SOAP over REST? Here is an example of the possible SOAP message:
<soap:Envelope>
<soap:Header>
<Credentials>
<User>Joe</User>
<Password>abc123</Password>
</Credentials>
</soap:Header>
<soap:Body>
<MyComplexBusinessObject>
<Search>
<First>Joe</First>
<Last>Smith</Last>
</Search>
...
...
</MyComplexBusinessObject>
</soap:Body>
</soap:Envelope>
使用 REST,我会要求客户端发布以下 xml 并使用基本身份验证进行身份验证:
Using REST, I would be asking the client to POST the following xml and authenticate using Basic Authentication:
<MyComplexBusinessObject>
<Search>
<First>Joe</First>
<Last>Smith</Last>
</Search>
...
...
</MyComplexBusinessObject>
SOAP 消息稍微复杂一些,但并不复杂.它们仍然都是 XML,但 SOAP 带有 WSDL,大多数编程环境都会为您生成代理类.但是,与我交谈的大多数人都说我应该改用 REST,因为它更易于使用.但我不认为 SOAP 更难使用.
The SOAP message is slightly more complicated, but not by much. They are still both XML, but SOAP comes with a WSDL and most programming environments will generate proxy classes for you. However, most people I talk to say I should use REST instead because it's easier to use. But I don't see how SOAP is any harder to use.
我错过了什么吗?
推荐答案
来回传递复杂对象"的第一个要求限制了您的架构以消除 REST 的许多好处.SOAP 设计用于访问远程对象,而 REST 不是.REST 支持传递像 text/plain 这样简单的媒体类型,这比处理对象要原始得多.
Your first requirement of "passing back and forth a complex object" constrains your architecture to eliminate many of the benefits of REST. SOAP is designed for accessing remote objects, REST is not. REST supports passing media-types as simple as text/plain, which is far more primitive than dealing with an object.
如果你还没有看过,this 问题及其答案涵盖了大多数 REST 与 SOAP 问题.
If you haven't seen it already, this question and its answers cover most of the REST vs SOAP issues.
这篇关于为什么比 SOAP 更喜欢 REST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!