xml 为什么 SOAP 消息必须通过 HTTP 发送?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4540301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:28:11  来源:igfitidea点击:

Why does a SOAP message have to be sent over HTTP?

xmlsoapnetwork-programmingprotocolswebservice-client

提问by smwikipedia

Below is a demo SOAP request message:

下面是一个演示 SOAP 请求消息:

HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn

    <SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   <SOAP-ENV:Header>
       <t:SessionOrder
         xmlns:t="http://example.com"
         xsi:type="xsd:int" mustUnderstand="1">
           5
       </t:SessionOrder>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
       <GetStockQuote
         xmlns="http://someexample.com">
           <Price>MSFT</Price>
       </GetStockQuote>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And we can see, this SOAP message is encoded as if it is a web page. Why do we have to use the HTTP protocol? SOAP message is just some XML, why not we just use XML as the information exchange protocol and get rid of the HTTP headers (thus leave HTTP alone).

我们可以看到,这个 SOAP 消息被编码为一个网页。为什么一定要使用HTTP协议?SOAP 消息只是一些 XML,为什么我们不直接使用 XML 作为信息交换协议并去掉 HTTP 标头(因此不理会 HTTP)。

Many thanks.

非常感谢。

Update - 1

更新 - 1

HTTP is not a transport level protocol. It is just a application-level protocol. It has nothing to do with transport. Actually, my question is what's the motive of adding HTTP stuff to a SOAP message?

HTTP 不是传输级协议。它只是一个应用程序级协议。它与运输无关。实际上,我的问题是向 SOAP 消息添加 HTTP 内容的动机是什么?

回答by Cratylus

Overview

概述

SOAPis a messaging protocoland in a nutshell is just another XML language.
Its purpose is the data exchange over networks. Its concern is the encapsulation of these data and the rules for transmitting and receiving them.

SOAP是一种消息传递协议,简而言之,它只是另一种 XML 语言。
其目的是通过网络进行数据交换。它关心的是这些数据的封装以及传输和接收它们的规则。

HTTPis an application protocoland SOAP messages are placed as the HTTP payload.
Although there is the overhead of HTTP, it has the advantage that it is a protocol that is open to firewalls, well-understood and widely-supported. Thus, web services can be accessed and exposed via technology already in-place.

HTTP是一种应用程序协议,SOAP 消息作为 HTTP 有效负载放置。
虽然有 HTTP 的开销,但它的优点是它是一个对防火墙开放的协议,易于理解和广泛支持。因此,可以通过现有技术访问和公开 Web 服务。

SOAP messages are usually exchanged via HTTP. Although it is possible to use other (application) protocols, e.g. SMTPor FTP, the non-HTTP bindings are not specified by SOAP specs and are not supported by WS-BP (interoperability spec).
You could exchange SOAP messages over raw TCP but then you would have web services that are not interoperable (not compliant to WS-BP).

SOAP 消息通常通过HTTP进行交换。尽管可以使用其他(应用程序)协议,例如SMTPFTP,但非 HTTP 绑定不是由 SOAP 规范指定的,并且不受WS-BP(互操作性规范)的支持
您可以通过原始 TCP 交换 SOAP 消息,但随后您将拥有不可互操作的 Web 服务(不符合 WS-BP)。

Nowadays the debate is why have the SOAP overhead at all and not send data over HTTP (RESTful WS).

现在的争论是为什么要使用 SOAP 开销而不是通过 HTTP ( RESTful WS)发送数据。

Why use HTTPfor SOAP?

为什么对SOAP使用HTTP

I will try to address in more detail the question in the OP, asking why use HTTP for SOAP:

我将尝试更详细地解决 OP 中的问题,询问为什么对 SOAP 使用 HTTP:

First of all SOAP defines a data encapsulation format and that's that.
Now the majority of traffic in the web is via HTTP. HTTP is literary EVERYWHERE and supported by a well-established infrastructure of servers and clients(namely browsers). Additionally it is a very well understood protocol.

首先,SOAP 定义了数据封装格式,仅此而已。
现在网络中的大部分流量都是通过 HTTP 进行的。HTTP 无处不在,并得到完善的服务器和客户端(即浏览器)基础设施的支持。此外,它是一个很好理解的协议。

The people who created SOAP wanted to use this ready infrastructure and

创建 SOAP 的人想要使用这个现成的基础设施,并且

  1. SOAP messages were designed so that they can be tunneled over HTTP
  2. In the specs they do not refer to any other non-HTTP binding but specifically refer to HTTP as an example for transfer.
  1. SOAP 消息被设计为可以通过 HTTP 隧道传输
  2. 在规范中,它们没有引用任何其他非 HTTP 绑定,而是专门引用 HTTP 作为传输示例。

The tunneling over HTTP would and did help in it's rapid adoption. Because the infrastructure of HTTP is already in-place, companies would not have to spend extra money for another kind of implementation. Instead they can expose and access web services using technology already deployed.

HTTP 上的隧道将会并且确实有助于它的快速采用。因为 HTTP 的基础设施已经就位,公司不必为另一种实现方式花费额外的钱。相反,他们可以使用已部署的技术公开和访问 Web 服务。

Specifically in Javaa web service can be deployed either as a servlet endpoint or as an EJB endpoint. So all the underlying network sockets, threads, streams, HTTP transactions etc. are handled by the container and the developer focuses only on the XML payload.
So a company has Tomcat or JBoss running in port 80 and the web service is deployed and accessible as well. There is no effort to do programming at the transport layer and the robust container handles everything else.
Finally the fact that firewalls are configured not to restrict HTTP traffic is a third reason to prefer HTTP.

特别是在Java 中,Web 服务可以部署为 servlet 端点或 EJB 端点。因此所有底层网络套接字、线程、流、HTTP 事务等都由容器处理,开发人员只关注 XML 负载。
因此,一家公司在端口 80 上运行 Tomcat 或 JBoss,并且 Web 服务也已部署和可访问。无需在传输层进行编程,而健壮的容器可以处理其他一切。
最后,防火墙配置为不限制 HTTP 流量的事实是首选 HTTP 的第三个原因。

Since HTTP traffic is usually allowed, the communication of clients/servers is much easier and web services can function without network security blockers issues as a result of the HTTP tunneling.

由于通常允许 HTTP 流量,因此客户端/服务器的通信要容易得多,并且 Web 服务可以正常运行,而不会因 HTTP 隧道而导致网络安全阻塞问题。

SOAP is XML=plain text so firewalls could inspect the content of HTTP body and block accordingly. But in this case they could also be enhanced to reject or accept SOAP depending on the contents.This part which seems to trouble you is not related to web services or SOAP, and perhaps you should start a new thread concerning how firewalls work.

SOAP 是 XML=plain text,因此防火墙可以检查 HTTP 正文的内容并相应地阻止。但在这种情况下,它们也可以增强以根据内容拒绝或接受 SOAP。这部分似乎给您带来麻烦的部分与 Web 服务或 SOAP 无关,也许您应该开始一个关于防火墙如何工作的新线程。

Having said that, the fact that HTTP traffic is unrestricted often causes security issues since firewalls are essentially by-passed, and that is why application-gateways come in.
But this is not related to this post.

话虽如此,HTTP 流量不受限制的事实通常会导致安全问题,因为防火墙本质上是被绕过的,这就是应用程序网关进来的原因。
但这与这篇文章无关。

Summary

概括

So to sum up the reasons for using HTTP:

所以总结一下使用HTTP的原因:

  1. HTTP is popular and successful.
  2. HTTP infrastructure is in place so no extra cost to deploy web services.
  3. HTTP traffic is open to firewalls, so there are no problems during web service functioning as a result of network security.
  1. HTTP 很流行并且很成功。
  2. HTTP 基础设施到位,因此部署 Web 服务无需额外成本。
  3. HTTP 流量对防火墙开放,因此出于网络安全的考虑,Web 服务运行期间不会出现问题。

回答by Emil Vikstr?m

SOAP can be sent over different transports. HTTP is just one of them.

SOAP 可以通过不同的传输方式发送。HTTP 只是其中之一。

回答by Andrew T Finnell

The motive of using HTTP was to get through firewalls. You see most network IT people do not allow just any port to be open, but for some reason they always allowed port 80 to be open for web pages. Because web servers have been tested over the years it is "easier" to secure them. By using HTTP you have an existing set of tools for dealing with a communications protocol.

使用 HTTP 的动机是为了通过防火墙。您会看到大多数网络 IT 人员不允许只打开任何端口,但出于某种原因,他们总是允许为网页打开端口 80。由于 Web 服务器已经经过多年测试,因此保护它们“更容易”。通过使用 HTTP,您拥有一组现有的工具来处理通信协议。

回答by Numenor

you can use TCP too and that was named .NET Remoting before and now its part of WCF...

你也可以使用 TCP,它之前被命名为 .NET Remoting,现在它是 WCF 的一部分......

回答by Sudip Bhandari

SOAP doesn't have to be sent over HTTP. Developers most frequently use HTTP and POST the soap as if it were a normal HTTP POST because we are most probably more familiar with HTTP than other protocols like SMTP, add this to the fact that we already implement REST over HTTP. For example here is how we send SOAP over SMTP email protocol. Sending SOAP over SMTP

SOAP 不必通过 HTTP 发送。开发人员最常使用 HTTP 和 POST 肥皂,就好像它是一个普通的 HTTP POST,因为我们很可能比其他协议(如 SMTP)更熟悉 HTTP,再加上我们已经通过 HTTP 实现了 REST 的事实。例如,这里是我们如何通过 SMTP 电子邮件协议发送 SOAP。通过 SMTP 发送 SOAP

It's just a common practice to use HTTP

使用HTTP只是一种常见的做法

回答by Damian Leszczyński - Vash

It is up to developer to choose the transfer layer for Simple Object Access Protocol. The XML is not a network protocol so the data cant be transfered using just XML. It has to be packed into something.

由开发人员选择简单对象访问协议的传输层。XML 不是网络协议,因此不能仅使用 XML 传输数据。它必须被打包成某种东西。

回答by Stuggi

Another reason might be that (if I remember correctly) HTTP is also designated as a "gold standard" for how an internet protocol is supposed to look/work, so if you were to develop an own protocol, you'd basically (in an ideal world at least) end up with something very similar if you followed all the RFCs. Therefore, why not use HTTP, one of the worlds most common and well understood protocols.

另一个原因可能是(如果我没记错的话)HTTP 也被指定为互联网协议外观/工作方式的“黄金标准”,因此如果您要开发自己的协议,您基本上(在一个至少理想世界)如果您遵循所有 RFC,最终会得到非常相似的结果。因此,为什么不使用 HTTP,它是世界上最常见和最容易理解的协议之一。

回答by yogesh wanjari

Basically SOAP is the web services standard that contains descriptions of the message which in the form of XML. That message structure will passed at time of web service called by service requester. In SOA architecture one of the most important characteristic is interoperability, in SOA SOAP play massive role that passed via HTTP/HTTPS and therefore can cross the firewalls, other architecture like DCOM, CORBA and RPC does not cross the firewall.

基本上 SOAP 是 Web 服务标准,它包含 XML 形式的消息描述。该消息结构将在服务请求者调用 Web 服务时传递。SOA架构中最重要的特性之一是互操作性,在SOA中SOAP扮演着重要的角色,通过HTTP/HTTPS传递,因此可以跨越防火墙,其他架构如DCOM、CORBA和RPC不跨越防火墙。

回答by SULAVA SINGHA MAHAPATRA

All the browsers supports HTTP for compatibility and its the most widely used Internet Protocol. SOAP is a communication protocol that specifies the format for sending messages. RPC and CORBA has compatibility and security issues, whereas HTTP is compatible with all the browsers. Now that HTTP communicates over TCP/IP. A SOAP method is an HTTP request/HTTP response that compiles with the SOAP encoding rules. using SOAP, a protocol submitted to the W3C data can be enclosed in XML and transmitted using any number of Internet Protocols.

所有浏览器都支持 HTTP 的兼容性及其最广泛使用的 Internet 协议。SOAP 是一种通信协议,用于指定发送消息的格式。RPC 和 CORBA 存在兼容性和安全性问题,而 HTTP 与所有浏览器兼容。现在 HTTP 通过 TCP/IP 进行通信。SOAP 方法是使用 SOAP 编码规则编译的 HTTP 请求/HTTP 响应。使用 SOAP,提交给 W3C 数据的协议可以包含在 XML 中,并使用任意数量的 Internet 协议进行传输。