Latest web development tutorials

SOAP Header 元素

可選的SOAP Header 元素包含頭部信息。


SOAP Header 元素

可選的SOAP Header 元素可包含有關SOAP 消息的應用程序專用信息(比如認證、支付等)。

如果Header 元素被提供,則它必須是Envelope 元素的第一個子元素。

注意:所有Header元素的直接子元素必須是合格的命名空間。

<?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:Header>
<m:Trans xmlns:m="http://www.w3schools.com/transaction/"
soap:mustUnderstand="1">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>

上面的例子包含了一個帶有一個"Trans" 元素的頭部,它的值是234,此元素的"mustUnderstand" 屬性的值是"1"。

SOAP 在默認的命名空間中("http://www.w3.org/2001/12/soap-envelope") 定義了三個屬性。

這三個屬性是:actor、 mustUnderstand 以及encodingStyle。 這些被定義在SOAP 頭部的屬性可定義容器如何對SOAP 消息進行處理。


mustUnderstand 屬性

SOAP 的mustUnderstand 屬性可用於標識標題項對於要對其進行處理的接收者來說是強制的還是可選的。

假如您向Header 元素的某個子元素添加了"mustUnderstand="1",則它可指示處理此頭部的接收者必須認可此元素。假如此接收者無法認可此元素,則在處理此頭部時必須失效。

語法

soap:mustUnderstand="0|1"

實例

<?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:Header>
<m:Trans xmlns:m="http://www.w3schools.com/transaction/"
soap:mustUnderstand="1">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>


actor 屬性

通過沿著消息路徑經過不同的端點,SOAP 消息可從某個發送者傳播到某個接收者。 並非SOAP 消息的所有部分均打算傳送到SOAP 消息的最終端點,不過,另一個方面,也許打算傳送給消息路徑上的一個或多個端點。

SOAP 的actor 屬性可被用於將Header 元素尋址到一個特定的端點。

語法

soap:actor="URI"

實例

<?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:Header>
<m:Trans xmlns:m="http://www.w3schools.com/transaction/"
soap:actor="http://www.w3schools.com/appml/">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>


encodingStyle 屬性

SOAP 的encodingStyle 屬性用於定義在文檔中使用的數據類型。 此屬性可出現在任何SOAP 元素中,並會被應用到元素的內容及元素的所有子元素上。

SOAP 消息沒有默認的編碼方式。

語法

soap:encodingStyle="URI"