SOAP - 信封



SOAP 信封指示消息的开始和结束,以便接收者知道何时已接收完整消息。SOAP 信封解决了知道何时完成接收消息并准备好处理它的问题。因此,SOAP 信封基本上是一种打包机制。

注意事项

  • 每个 SOAP 消息都有一个根 Envelope 元素。

  • Envelope 是 SOAP 消息的必备部分。

  • 每个 Envelope 元素必须包含且仅包含一个 Body 元素。

  • 如果 Envelope 包含 Header 元素,则最多只能包含一个,并且必须作为 Envelope 的第一个子元素出现在 Body 之前。

  • SOAP 版本更改时,信封也会发生更改。

  • SOAP 信封使用ENV命名空间前缀和 Envelope 元素指定。

  • 可选的 SOAP 编码也使用命名空间名称和可选的encodingStyle元素指定,该元素也可以指向除 SOAP 编码之外的其他编码样式。

  • 符合 v1.1 的 SOAP 处理器在接收到包含 v1.2 信封命名空间的消息时会生成故障。

  • 符合 v1.2 的 SOAP 处理器如果接收到不包含 v1.2 信封命名空间的消息,则会生成VersionMismatch故障。

符合 v1.2 的 SOAP 消息

下面是一个符合 v1.2 的 SOAP 消息示例。

<?xml version = "1.0"?>
<SOAP-ENV:Envelope 
   xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope" 
   SOAP-ENV:encodingStyle = " http://www.w3.org/2001/12/soap-encoding">
   ...
   Message information goes here
   ...
</SOAP-ENV:Envelope>

使用 HTTP POST 的 SOAP

以下示例说明了在 HTTP POST 操作中使用 SOAP 消息的情况,该操作将消息发送到服务器。它显示了信封模式定义和编码规则模式定义的命名空间。HTTP 头中的OrderEntry引用是要在 tutorialspoint.com 网站上调用的程序的名称。

POST /OrderEntry HTTP/1.1
Host: www.tutorialspoint.com
Content-Type: application/soap;  charset="utf-8"
Content-Length: nnnn

<?xml version = "1.0"?>
<SOAP-ENV:Envelope 
   xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope" 
   SOAP-ENV:encodingStyle = " http://www.w3.org/2001/12/soap-encoding">
   ...
   Message information goes here
   ...
</SOAP-ENV:Envelope>

注意 - HTTP 绑定指定服务的地址。

广告