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屬性:定義在文檔中使用的數據類型
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章