SOAP 与 REST,何时使用一个而不是另一个? [英] SOAP vs REST, when to use one and not the other?

查看:23
本文介绍了SOAP 与 REST,何时使用一个而不是另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次遇到这个问题时,我真的很困惑,哪些特征会帮助人们选择 SOAP 而不是 REST 或相反?

I'm really confused everytime I come around this question, what characteristics would help one choosing SOAP over REST or the other way around?

我的意思是,除了 REST 与 SOAP 相比具有紧凑的格式以及其他次要"或技术"差异之外,还有哪些明显"差异使其中一个更适合项目而不是另一个?

I mean, besides the fact that REST has a compact format compared to SOAP, and the other "minor" or "technical" differences, what are the "obvious" differences that make one of them more suitable for a project and not the other?

只是为了记录,我已经阅读了所有其他问题(1|2|3|4) 关于 Stack Overflow 上的这件事,没有一个人回答了我的问题.

Just for the record, I have read all of the other questions (1|2|3|4) regarding this matter on Stack Overflow, and not one of them answered my question.

推荐答案

REST 和 SOAP 之间的区别是根本性的,但它们并没有不同.最终,您仍然需要传输完全相同的信息才能执行特定的抽象操作.通过选择糟糕的返回信息,很容易使 REST 的性能变得相当低,并且带有 MTOM 的 SOAP 可以有效地传输大型二进制块.甚至可以将非 XML 编码和连接传输(例如 XMPP)与 SOAP 结合使用,从而使其比 REST 更高效.

The difference between REST and SOAP is fundamental, yet they're not that dissimilar. Ultimately, you still need to transfer exactly the same information in order to perform a particular abstract operation. It's entirely easy to make REST rather low-performing by choosing poorly what information to return, and SOAP with MTOM can transfer large binary chunks efficiently. There's even the possibility to use non-XML encodings and connected transports (e.g., XMPP) with SOAP that can make it more efficient than REST.

所以不用担心!

需要考虑的更相关的事情是,SOAP 继续在某些语言中提供更高级的工具支持,而其他语言则更喜欢 REST.例如,如果您想要一个 Java 客户端用于您的服务,您将能够在几分钟内开始使用 SOAP:只需通过工具引擎放置 WSDL 位置,您就拥有了一个基本客户端.另一方面,如果您使用 Javascript 客户端,那么您绝对更喜欢使用 REST 接口;Javascript 与 REST 配合使用很棒.

A much more relevant thing to think about is that SOAP continues to have significantly more advanced tooling support in some languages, and that other languages strongly prefer REST. For example, if you want a Java client for your service, you'll be able to get going with SOAP in minutes: just put the WSDL location through a tooling engine and you've got yourself a basic client. On the other hand, if you're working with a Javascript client then you'll absolutely prefer to deal with the REST interface; Javascript works great with REST.

这里要注意的一个关键点是,您可以让您的服务同时支持 SOAP 和 REST(您可能需要将它们放在不同的端点上,但这并不是很麻烦).我使用我支持的服务(使用 Java 和 Apache CXF)执行此操作,并且两者的开销很小:关键是我需要一个 SOAP 和 REST 接口都使用的幕后干净的抽象接口.

A key thing to note here is that you can have your service support both SOAP and REST at once (you might need to put them on different endpoints, but that's not very onerous). I do this with a service I support (using Java and Apache CXF) and the overhead of doing both is minimal: the key is that I need a clean abstract interface behind the scenes that both the SOAP and REST interfaces use.

这篇关于SOAP 与 REST,何时使用一个而不是另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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