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 繫結指定服務的地址。

廣告