直播中
SOAP
v1.2為在一個(gè)松散的、分布的環(huán)境中使用XML對(duì)等地交換結(jié)構(gòu)化的和類型化的信息提供了一個(gè)簡(jiǎn)單且輕量級(jí)的機(jī)制。SOAP本身并不定義任何應(yīng)用語(yǔ)義,如編程模型或特定語(yǔ)義實(shí)現(xiàn),它只是定義了一種簡(jiǎn)單的機(jī)制,通過(guò)一個(gè)模塊化的包裝模型和對(duì)模塊中特定格式編碼的數(shù)據(jù)的重編碼機(jī)制來(lái)表示應(yīng)用語(yǔ)義。SOAP的這項(xiàng)能力使得它可被很多類型的系統(tǒng)用于從消息系統(tǒng)到RPC(Remote
Procedure Call)的延伸。
SOAP由四部分組成:
SOAP envelop (SOAP信封,參閱 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383494">section
4),它構(gòu)造定義了一個(gè)整體的表示框架,可用于表示在消息(message)中的是什么,誰(shuí)應(yīng)當(dāng)處理它,以及這是可選的
還是強(qiáng)制的。
SOAP encoding rules (SOAP編碼規(guī)則,參閱 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383512">section
5),定義了一個(gè)編序機(jī)制用于交換應(yīng)用程序定義的數(shù)據(jù)類型的實(shí)例。
SOAP RPC representation (SOAP RPC表示,參閱 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383532">section
7),定義了一個(gè)用于表示遠(yuǎn)端過(guò)程調(diào)用和響應(yīng)的約定。
SOAP binding (SOAP綁定,參閱 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383526">section
6) 定義了一個(gè)使用底層傳輸協(xié)議來(lái)完成在結(jié)點(diǎn)間交換SOAP信封的約定。
為了簡(jiǎn)化本規(guī)范,這四部分在功能上是正交的。特別的,信封和編碼規(guī)則是被定義在不同的命名空間(namespace)中,這樣有利于通過(guò)模塊化獲得簡(jiǎn)明性。
本規(guī)范還定義了兩種SOAP綁定(binding),用于描述SOAP消息(message)如何通過(guò)帶或不帶HTTP擴(kuò)展框架 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#RFC2774">[6](HTTP
Extension Framework)的HTTP href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#RFC2616">[5]消息(message)進(jìn)行傳輸。
1.1 設(shè)計(jì)目標(biāo)
SOAP的主要設(shè)計(jì)目標(biāo)是簡(jiǎn)明性和可擴(kuò)展性。這就意味著有一些傳統(tǒng)消息系統(tǒng)或分布式對(duì)象系統(tǒng)中的特性將不包含在SOAP的核心規(guī)范中。這些特性包括:
分布式垃圾收集 (distributed garbage collection);
批量消息傳輸/處理 (boxcarring or batching of messages);
對(duì)象引用 (objects-by-reference, 需要分布式垃圾收集的支持);
對(duì)象激活 (activation, 需要對(duì)象引用的支持)。
1.2 符號(hào)約定
本文中的關(guān)鍵詞“MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”,
“SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”,
“OPTIONAL”的語(yǔ)義應(yīng)當(dāng)參閱RFC-2119 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#RFC2119">[2]。在本中文版規(guī)范中被翻譯成:“必須”、“必須不”,“需要的”,“將”,“將不”,“應(yīng)該”,“應(yīng)該不”,“被推薦的”,“可以”,“可選的”。
本文中使用的命名空間前綴“env”和“enc”等關(guān)聯(lián)的SOAP命名空間分別位于以下位置:"
和"
和" 相關(guān)聯(lián)的,這是由XML
Schemas規(guī)范[ href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#XMLS1">10, href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#XMLS2">11]所定義的。
值得注意的是其他的對(duì)命名空間前綴的使用都是比較隨意的而并沒(méi)有顯著語(yǔ)義的約束的。
若命名空間的URI使用"http://example.org/..."或"http://example.com/..."的形式,表明這是一些應(yīng)用依賴或上下文依賴的URI href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#RFC2396">[4]。
本規(guī)范使用擴(kuò)充BNF(Backus-Naur Form)作為構(gòu)造語(yǔ)言,可參閱RFC-2612 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#RFC2616">[5]。
編輯的注解將使用黃色背景標(biāo)識(shí)(也許無(wú)法在所有的媒介上顯示),并使用前綴"Ednote"。
1.3 SOAP消息示例
第一個(gè)例子展示了一個(gè)使用SOAP表示的簡(jiǎn)單的通知消息。該消息包含了一個(gè)消息頭"alertcontrol"和消息體"alert",這兩部分都是由應(yīng)用程序定義的,而而并不是由SOAP定義的。消息頭包含了兩個(gè)參數(shù)"priority"和"expires",用于消息傳輸中介和消息接受者對(duì)消息的處理。而消息體中則包含是實(shí)際傳送的消息。
Example 0
1 2001-06-22T14:00:00-05:00 Pick up Mary at school at 2pm
Sample SOAP Message containing a header
block and a body block
SOAP消息能夠與不同的底層協(xié)議進(jìn)行綁定,同時(shí)可以在很多種消息傳輸模式中使用。下面的例子則展示了SOAP是如何在HTTP的連接中使用的,其中充分使用了HTTP提供的請(qǐng)求/相應(yīng)機(jī)制(參閱
href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383526">section
6)。
Example 1和Example
2展示了一個(gè)SOAP/HTTP請(qǐng)求的例子和一個(gè)SOAP/HTTP響應(yīng)的例子。SOAP/HTTP請(qǐng)求包含了一個(gè)獲取最后交易價(jià)格(GetLastTradePrice)的信息塊,其中包含了一個(gè)簡(jiǎn)單的參數(shù),指明需要報(bào)價(jià)的股票代號(hào)。同樣,與先前的例子相似,GetLastTradePrice這個(gè)XML元素也并不是由SOAP自身定義的。該請(qǐng)求的服務(wù)響應(yīng)也包含了一個(gè)簡(jiǎn)單的參數(shù),股票的價(jià)格。SOAP信封元素是表示SOAP消息的XML文檔的頂級(jí)元素。XML命名空間則用來(lái)消除SOAP標(biāo)識(shí)符與應(yīng)用定義的標(biāo)識(shí)符之間可能存在的歧義。
Example 1
POST /StockQuote HTTP/1.1Host: www.stockquoteserver.comContent-Type: text/xml; charset="utf-8"Content-Length: nnnnSOAPAction: "http://example.org/2001/06/quotes" env:encodingStyle="http://www.w3.org/2001/06/soap-encoding" xmlns:m="http://example.org/2001/06/quotes"> DIS
Sample SOAP Message embedded in an HTTP
Request
Example 2展示了StockQuote服務(wù)響應(yīng)由 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Ref477488396">Example
1描述的請(qǐng)求消息而返回的SOAP消息。
Example 2
HTTP/1.1 200 OKContent-Type: text/xml; charset="utf-8"Content-Length: nnnn env:encodingStyle="http://www.w3.org/2001/06/soap-encoding" xmlns:m="http://example.org/2001/06/quotes"> 34.5
Sample SOAP Message embedded in an HTTP
Response
在 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383539">Appendix
A中提供了更多的例子。
1.4 SOAP術(shù)語(yǔ)
1.4.1 協(xié)議概念
SOAP
關(guān)于 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息的格式和 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#_Toc478383605">處理規(guī)則、為沿著 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑交換信息而需要的不同應(yīng)用程序之間 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g110">生成和 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g120">接收SOAP消息的交互過(guò)程的簡(jiǎn)單控制機(jī)制等的一整套規(guī)范和約定。
SOAP綁定
為傳輸?shù)男枰鴮OAP消息在另一個(gè)底層協(xié)議之上或之內(nèi)傳輸?shù)囊徽滓?guī)范和規(guī)則。典型的SOAP綁定包括在HTTP消息中傳送SOAP消息或在TCP之上傳送SOAP消息等。
SOAP結(jié)點(diǎn)
SOAP結(jié)點(diǎn)根據(jù) href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g330">SOAP定義的整套規(guī)范來(lái)處理 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息。SOAP結(jié)點(diǎn)有責(zé)任遵守SOAP消息交換的規(guī)則以及提供通過(guò)依賴底層協(xié)議的SOAP綁定來(lái)訪問(wèn)的服務(wù)。任何不符合SOAP約定的情況都將導(dǎo)致SOAP結(jié)點(diǎn)產(chǎn)生一個(gè) href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g230">SOAP錯(cuò)誤(可參閱 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g120">SOAP接受者和 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g110">SOAP發(fā)送者)。
1.4.2 數(shù)據(jù)封裝概念
SOAP消息
SOAP消息(message)是在對(duì)等SOAP結(jié)點(diǎn)( href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g105">SOAP
nodes)間通訊的基本單位。
SOAP信封
SOAP信封(envelope)是 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g330">SOAP規(guī)范中定義的SOAP消息( href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP
message)在句法上的最外層結(jié)構(gòu)。在句法上,它包含了所有其他的元素。
SOAP條目
SOAP條目是一個(gè)句法上的結(jié)構(gòu),它用于包含一個(gè)邏輯上的單一元素,這一元素是需要被 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g105">SOAP結(jié)點(diǎn)處理的。一個(gè)SOAP條目是由該條目最外層元素的完整修飾名所標(biāo)識(shí)的,這個(gè)完整修飾名是由一個(gè)局部名和一個(gè)命名空間URI組成的。封裝在 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g210">SOAP
header中的SOAP條目成為Header條目,而封裝在 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g200">SOAP
body中的SOAP條目為Body條目。
SOAP header
能夠被 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑中任意的SOAP接受者處理的一組 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g400">SOAP條目(0個(gè)或多個(gè))。
SOAP body
能夠被 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑中的 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g130">最終SOAP接受者處理的一組 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g400">SOAP條目(0個(gè)或多個(gè))。
SOAP fault
href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g105">SOAP結(jié)點(diǎn)產(chǎn)生的用于包含錯(cuò)誤信息的特殊的 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g400">SOAP條目。
以下的圖表演示了一個(gè)SOAP消息是如何組成的。
Figure 1: Encapsulation model illustrating the
parts of a SOAP message
1.4.3 消息發(fā)送者和接收者概念
SOAP發(fā)送者
SOAP發(fā)送者是發(fā)出SOAP消息的 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g105">SOAP結(jié)點(diǎn)。
SOAP接收者
SOAP接收者是接受SOAP消息的 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g105">SOAP結(jié)點(diǎn)。
SOAP消息路徑
為傳送一個(gè)簡(jiǎn)單的 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息而要經(jīng)過(guò)的一組 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g110">SOAP發(fā)送者和 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g120">SOAP接受者。其中包含了 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g340">初始SOAP發(fā)送者、零個(gè)或多個(gè) href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g140">SOAP中介以及 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g130">最終SOAP接受者。
初始SOAP發(fā)送者
href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息的最初產(chǎn)生者,同時(shí)也是 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑的第一個(gè)結(jié)點(diǎn)。
SOAP中介
SOAP中介即是 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g120">SOAP接收者也是 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g110">SOAP發(fā)送者,是 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息可到達(dá)的某一個(gè)應(yīng)用程序。當(dāng) href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息沿著 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑傳輸時(shí),SOAP中介將處理一組確定的SOAP條目,然后它將消息轉(zhuǎn)發(fā)給消息路徑的下一個(gè)SOAP結(jié)點(diǎn),直至傳送到 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g130">最終SOAP接收者。
最終SOAP接收者
由 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g340">初始SOAP發(fā)送者指定的通過(guò) href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑傳送 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息的最終 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g120">SOAP接收者。如果在 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g100">SOAP消息路徑中有 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g105">SOAP結(jié)點(diǎn)產(chǎn)生了 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g230">SOAP錯(cuò)誤,那么 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息將不會(huì)到達(dá)最終接收者。
1.4.4 數(shù)據(jù)編碼概念
SOAP數(shù)據(jù)模型
一組抽象的構(gòu)造約定,用于描述通用的數(shù)據(jù)類型和數(shù)據(jù)中的鏈接關(guān)系。
SOAP數(shù)據(jù)編碼
在 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g170">SOAP消息中使用一個(gè)或多個(gè)SOAP條目,按照 href="file:///F:/Documents%20and%20Settings/Fennivel/My%20Documents/tWork.Web.Service/2-SOAP/SOAP%20Version%201_2.htm#g270">SOAP數(shù)據(jù)模型完成句法上的數(shù)據(jù)表示。