为什么将 SOAP 用于 Web 服务? [英] Why use SOAP for webservices?

查看:41
本文介绍了为什么将 SOAP 用于 Web 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读教程web-service-php-mysql-xml-json".

看起来一切正常.但是,为什么我们应该为 Web 服务使用肥皂?

It seems everything is ok. But then why we should use soap for web services?

推荐答案

在构建 Web 服务时,您可以通过两种方式:

When building web services you can go two ways:

  • 肥皂
  • 休息

大多数人选择阻力较小的路径,即REST.这意味着简单、易于开发、以预期的方式使用 HTTP、充分利用缓存代理、更易读的结果等.

Most people choose the path of less resistance, which is REST. This means simplicity, ease of development, using HTTP the way it's meant to be used, make good use of cache proxies, more human readable results etc.

SOAP 在另一端比 REST 更重量级,并且还得到了大量 规范.但是因为它更复杂(SOAP 曾经是 Simple Object Access Protocol 的首字母缩写词 - 事实证明它是......不是)很多人不喜欢 SOAP.

SOAP on the other end is more heavyweight than REST and is also backed up by a large set of specifications. But because it is more complex (SOAP used to be the acronym for Simple Object Access Protocol – which proved to be... NOT) SOAP is not liked by lots of people.

两种方法都有效,各有优缺点.

例如,SOAP 可以使用任何传输协议,而不仅仅是 HTTP(S),SOAP 在安全性方面提供更多选择,SOAP 提供可靠的消息传递等.另一方面,REST 允许许多不同类型的数据格式,由于 JSON 格式,REST 可以更好地支持浏览器,REST 具有更好的性能等等.

For example, SOAP can make use of any transport protocol not just HTTP(S), SOAP offers more options when security is concerned, SOAP offers reliable messaging etc etc. REST on the other hand permits many different types of data formats, REST allows better support for browsers because of the JSON format, REST has better performance etc etc etc.

我不打算详细介绍,因为您可以在网络上找到很多 SOAP 与 REST 的比较.我想强调的一点是,在某些情况下,一种比另一种更有效,您可以根据自己的具体情况来决定和选择实施哪一种.

I’m not going to go into more details since you can find a lot of comparisons SOAP vs REST on the web. The thing that I want to emphasize is the fact that in some cases one works better than the other and it is up to you to determine and choose which one to implement given your particular case.

要回答您的问题:

为什么使用 SOAP 或 REST?如果没有它们,我们可以拥有网络服务吗?

why use SOAP or REST? we can have web service without them?

好吧,W3C 将 Web 服务定义为旨在支持可互操作的机器到网络上的机器交互".

Well, the W3C defines a web service as "a software system designed to support interoperable machine-to-machine interaction over a network".

好的...这是一个很好的定义.但这不是 SOAP/REST 的定义,可以在 通信协议 处理.

OK... that's nice for a definition. But this is not the definition for SOAP/REST, this requirement can be successfully thrown at a communication protocol to handle.

所以基本上,只要支持可互操作的机器对机器交互",您就可以使用任何您想要的通信协议(甚至创建您自己的)来拥有一个 Web 服务.这也意味着除 SOAP 或 REST 之外的其他东西(好吧……REST 不是协议,我只是在这里使用它作为参考来证明我的观点……所以请耐心等待).

So basically you could have a web service using whatever communication protocol you want (even creating your own) as long as is supports the "interoperable machine-to-machine interaction". This also means something else than SOAP or REST (OK... REST is not a protocol, I just use it here as reference to prove my point... so bear with me).

但是您创建网络服务是因为您希望一些客户使用您的服务.你的客户在狂野的西部(即网络:D),那里的人说 SOAP/REST.你过来说:我们真的不喜欢我们店里的 SOAP 和 REST,我们喜欢 RPC、CORBA 和我们自己独特的创造物Bone Crusher 10000"协议之类的东西.如果你想做跟我们做生意,你去学习碎骨机 10000"".你的客户会说(扬起眉毛)Yeaaaaah righttttt.....".

But you create a web service because you want some clients to use your service. And your clients are out there in the wild wild west (i.e. the web :D) and people there speak SOAP/REST. An there you come and say: "We relly don't like SOAP and REST here in our shop, we like stuff like RPC, CORBA and our own unique creation the "Bone Crusher 10000" protocol. If you want to do business with us, you go learn the "Bone Crusher 10000"". And your clients will say (eyebrow raised) "Yeaaaaah righttttt.....".

(我在这里假设你的协议不会是完全超越 SOAP/REST 的东西:D)

因此,如果您不使用 SOAP/REST,则会限制您的目标受众.就像英语一样.我的母语不是英语,是吗?好吧,这并不重要,因为我们能够用英语交流.想用冰岛语试试这个吗?.我学冰岛语的时候你会等我吗,因为那也不是我的母语?

So, if you don't use SOAP/REST you will limit your target audience. It's like English for example. I'm not a native English speaker, are you? Well, it does not really matter since we are able to communicate in English. Want to try this in Icelandic? . Will you wait for me while I learn Icelandic, cause that's not my native language either?

正如我已经说过的,根据您的特定情况决定和选择要实现的内容由您决定,但是如果您远离已知的技术堆栈,您就会丢弃随之而来的内容:<强>大量经验、资源、工具和沟通选项.

As I already said, it is up to you to determine and choose what to implement given your particular case, but if you move away from known technology stacks you throw away what comes with that: lots of experience, resources, tools and communication options.

作为最后的例子,今天有很多对 SOAP 协议的支持,您可以很容易地从 WSDL 文件开始生成客户端.而presto...您的客户可以与您的网络服务进行通信.使用Bone Crusher 10000"会不会如此简单?如果您编写工具、提供资源、支持等……是的!但这将花费您时间和金钱来创建已经发明并在今天被广泛使用的东西.

As a closing example, there's a lot of support for the SOAP protocol today and you can generate clients very easily starting from the WSDL file. And presto... your clients can communicate with your web service. Will it go as easy as this with "Bone Crusher 10000"? If you write the tools, provide the resources, support etc... Yes! But that will cost you time and money to create something that was already invented and is in wide use today.

这篇关于为什么将 SOAP 用于 Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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