`
applepieone
  • 浏览: 11207 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

SOAP实例

 
阅读更多

一个 SOAP 实例

在下面的例子中,一个 GetStockPrice 请求被发送到了服务器。此请求有一个 StockName 参数,而在响应中则会返回一个 Price 参数。此功能的命名空间被定义在此地址中: "http://www.example.org/stock",是应用程序专用的元素,而不是soap标准的一部分

 

SOAP Body 元素的直接子元素可以是合格的命名空间。SOAP 在默认的命名空间中("http://www.w3.org/2001/12/soap-envelope ")定义了 Body 元素内部的一个元素。是soap标准的一部分。

   SOAP 请求:

POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml ; charset=utf-8
Content-Length: nnn

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

<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice >
<m:StockName >IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>

</soap:Envelope>
 

   SOAP 响应:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

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

<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse >
<m:Price >34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>

</soap:Envelope>
 

    SOAP 构建模块

      一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素:

  • 必需 Envelope 元素,可把此 XML 文档标识为一条 SOAP 消息,根元素
  • 可选的 Header 元素,包含头部信息
  • 必需Body 元素,包含所有的调用和响应信息
  • 可选的 Fault 元素,提供有关在处理此消息所发生错误的信息,位于Body里面

    xmlns:soap 命名空间

       SOAP 消息必须拥有与命名空间 "http://www.w3.org/2001/12/soap-envelope" 相关联的一个 Envelope 元素。

 

    soap属性

      SOAP 在默认的命名空间中 ("http://www.w3.org/2001/12/soap-envelope") 定义了三个属性 。这三个属性是:actor、 mustUnderstand 以及 encodingStyle。这些被定义在 SOAP 头部的属性可定义容器如何对 SOAP 消息进行处理。

  •    actor属性:用于将 Header 元素寻址到一个特定的端点
  •    mustUnderstand属性:标识标题项对于要对其进行处理的接收者来说是强制的还是可选的。如果是1,接收者必须认可此元素。
  •    encodingStyle属性:定义在文档中使用的数据类型
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics