乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      SOAP協(xié)議是什么

       希望蠟炬 2013-01-22
      一、什么是 SOAP? 

          SOAP 指簡易對(duì)象訪問協(xié)議 
          SOAP 是一種通信協(xié)議 
          SOAP 用于應(yīng)用程序之間的通信 
          SOAP 是一種用于發(fā)送消息的格式 
          SOAP 被設(shè)計(jì)用來通過因特網(wǎng)進(jìn)行通信 
          SOAP 獨(dú)立于平臺(tái) 
          SOAP 獨(dú)立于語言 
          SOAP 基于 XML 
          SOAP 很簡單并可擴(kuò)展 
          SOAP 允許您繞過防火墻 
          SOAP 將被作為 W3C 標(biāo)準(zhǔn)來發(fā)展 


      二、為什么使用SOAP協(xié)議? 

      對(duì)于應(yīng)用程序開發(fā)來說,使程序之間進(jìn)行因特網(wǎng)通信是很重要的。 

      目前的應(yīng)用程序通過使用遠(yuǎn)程過程調(diào)用(RPC)在諸如 DCOM 與 CORBA 等對(duì)象之間進(jìn)行通信,但是 HTTP 不是為此設(shè)計(jì)的。RPC 會(huì)產(chǎn)生兼容性以及安全問題;防火墻和代理服務(wù)器通常會(huì)阻止此類流量。 

      通過 HTTP 在應(yīng)用程序間通信是更好的方法,因?yàn)?HTTP 得到了所有的因特網(wǎng)瀏覽器及服務(wù)器的支持。SOAP 就是被創(chuàng)造出來完成這個(gè)任務(wù)的。 

      SOAP 提供了一種標(biāo)準(zhǔn)的方法,使得運(yùn)行在不同的操作系統(tǒng)并使用不同的技術(shù)和編程語言的應(yīng)用程序可以互相進(jìn)行通信。 



      三、SOAP 構(gòu)建模塊 

      一條 SOAP 消息就是一個(gè)普通的 XML 文檔,包含下列元素: 

          必需的 Envelope 元素,可把此 XML 文檔標(biāo)識(shí)為一條 SOAP 消息 
          可選的 Header 元素,包含頭部信息 
          必需的 Body 元素,包含所有的調(diào)用和響應(yīng)信息 
          可選的 Fault 元素,提供有關(guān)在處理此消息所發(fā)生錯(cuò)誤的信息 

      所有以上的元素均被聲明于針對(duì) SOAP 封裝的默認(rèn)命名空間中: 

      http://www./2001/12/soap-envelope 

      以及針對(duì) SOAP 編碼和數(shù)據(jù)類型的默認(rèn)命名空間: 

      http://www./2001/12/soap-encoding 



      1,語法規(guī)則 

      這里是一些重要的語法規(guī)則: 

          SOAP 消息必須用 XML 來編碼 
          SOAP 消息必須使用 SOAP Envelope 命名空間 
          SOAP 消息必須使用 SOAP Encoding 命名空間 
          SOAP 消息不能包含 DTD 引用 
          SOAP 消息不能包含 XML 處理指令 

      (1)必須使用 SOAP Envelope 
      必需的 SOAP 的 Envelope 元素是 SOAP 消息的根元素。它可把 XML 文檔定義為 SOAP 消息。 

      請(qǐng)注意 xmlns:soap 命名空間的使用。它的值應(yīng)當(dāng)始終是:http://www./2001/12/soap-envelope 

      并且它可把封裝定義為 SOAP 封裝: 
      Xml代碼  收藏代碼
      1. <?xml version="1.0"?>  
      2. <soap:Envelope  
      3. xmlns:soap="http://www./2001/12/soap-envelope"  
      4. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      5.   ...  
      6.   Message information goes here  
      7.   ...  
      8. </soap:Envelope>  


      (2)必須使用 SOAP Encoding 
      SOAP 的 encodingStyle 屬性用于定義在文檔中使用的數(shù)據(jù)類型。此屬性可出現(xiàn)在任何 SOAP 元素中,并會(huì)被應(yīng)用到元素的內(nèi)容及元素的所有子元素上。SOAP 消息沒有默認(rèn)的編碼方式。 
      語法  soap:encodingStyle="URI" 


      注意: 
      SOAP 消息必須擁有與命名空間 "http://www./2001/12/soap-envelope" 相關(guān)聯(lián)的一個(gè) Envelope 元素。如果使用了不同的命名空間,應(yīng)用程序會(huì)發(fā)生錯(cuò)誤,并拋棄此消息。 


      2,SOAP Header 元素 

      可選的 SOAP Header 元素可包含有關(guān) SOAP 消息的應(yīng)用程序?qū)S眯畔ⅲū热缯J(rèn)證、支付等)。如果 Header 元素被提供,則它必須是 Envelope 元素的第一個(gè)子元素。 

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

      SOAP 在默認(rèn)的命名空間中 ("http://www./2001/12/soap-envelope") 定義了三個(gè)屬性。這三個(gè)屬性是:actor、 mustUnderstand 以及 encodingStyle。這些被定義在 SOAP 頭部的屬性可定義容器如何對(duì) SOAP 消息進(jìn)行處理。 

      (1)actor 屬性 
      通過沿著消息路徑經(jīng)過不同的端點(diǎn),SOAP 消息可從某個(gè)發(fā)送者傳播到某個(gè)接收者。并非 SOAP 消息的所有部分均打算傳送到 SOAP 消息的最終端點(diǎn),不過,另一個(gè)方面,也許打算傳送給消息路徑上的一個(gè)或多個(gè)端點(diǎn)。 

      SOAP 的 actor 屬性可被用于將 Header 元素尋址到一個(gè)特定的端點(diǎn)。 
      語法  soap:actor="URI" 

      實(shí)例 
      Xml代碼  收藏代碼
      1. <?xml version="1.0"?>  
      2. <soap:Envelope  
      3. xmlns:soap="http://www./2001/12/soap-envelope"  
      4. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      5.   
      6. <soap:Header>  
      7. <m:Trans  
      8. xmlns:m="http://www.w3school.com.cn/transaction/"  
      9. soap:actor="http://www.w3school.com.cn/appml/">  
      10. 234  
      11. </m:Trans>  
      12. </soap:Header>  
      13.   
      14. ...  
      15. ...  
      16.   
      17. </soap:Envelope>  


      (2)mustUnderstand 屬性 
      SOAP 的 mustUnderstand 屬性可用于標(biāo)識(shí)標(biāo)題項(xiàng)對(duì)于要對(duì)其進(jìn)行處理的接收者來說是強(qiáng)制的還是可選的。 

      假如您向 Header 元素的某個(gè)子元素添加了 "mustUnderstand="1",則它可指示處理此頭部的接收者必須認(rèn)可此元素。假如此接收者無法認(rèn)可此元素,則在處理此頭部時(shí)必須失效。 
      語法  soap:mustUnderstand="0|1" 

      實(shí)例 
      Xml代碼  收藏代碼
      1. <?xml version="1.0"?>  
      2. <soap:Envelope  
      3. xmlns:soap="http://www./2001/12/soap-envelope"  
      4. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      5.   
      6. <soap:Header>  
      7.     <m:Trans  
      8.         xmlns:m="http://www.w3school.com.cn/transaction/"  
      9.         soap:mustUnderstand="1">234  
      10.     </m:Trans>  
      11. </soap:Header>  
      12.   
      13. ...  
      14. ...  
      15.   
      16. </soap:Envelope>  


      (3)encodingStyle 屬性 
      SOAP 的 encodingStyle 屬性在前面已解釋過了。 



      3,SOAP Body 元素 

      SOAP Body 元素的直接子元素可以是合格的命名空間。SOAP 在默認(rèn)的命名空間中("http://www./2001/12/soap-envelope")定義了 Body 元素內(nèi)部的一個(gè)元素。即 SOAP 的 Fault 元素,用于指示錯(cuò)誤消息。 

      Xml代碼  收藏代碼
      1. <!--  一個(gè) SOAP 請(qǐng)求應(yīng)該類似這樣  -->  
      2. <?xml version="1.0"?>  
      3. <soap:Envelope  
      4. xmlns:soap="http://www./2001/12/soap-envelope"  
      5. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      6.   
      7. <soap:Body>  
      8.    <m:GetPrice xmlns:m="http://www.w3school.com.cn/prices">  
      9.       <m:Item>Apples</m:Item>  
      10.    </m:GetPrice>  
      11. </soap:Body>  
      12.   
      13. </soap:Envelope>  
      14.   
      15.   
      16. <!--  而一個(gè) SOAP 響應(yīng)應(yīng)該類似這樣:  -->  
      17. <?xml version="1.0"?>  
      18. <soap:Envelope  
      19. xmlns:soap="http://www./2001/12/soap-envelope"  
      20. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      21.   
      22. <soap:Body>  
      23.    <m:GetPriceResponse xmlns:m="http://www.w3school.com.cn/prices">  
      24.       <m:Price>1.90</m:Price>  
      25.    </m:GetPriceResponse>  
      26. </soap:Body>  
      27.   
      28. </soap:Envelope>  

      請(qǐng)注意,請(qǐng)求中的 m:GetPrice 和 Item 元素是應(yīng)用程序?qū)S玫脑亍K鼈儾⒉皇?SOAP 標(biāo)準(zhǔn)的一部分。 



      4,SOAP Fault 元素 

      可選的 SOAP Fault 元素用于指示錯(cuò)誤消息。 

      如果已提供了 Fault 元素,則它必須是 Body 元素的子元素。在一條 SOAP 消息中,F(xiàn)ault 元素只能出現(xiàn)一次。 

      SOAP 的 Fault 元素?fù)碛邢铝凶釉兀?nbsp;
      <faultcode> 供識(shí)別故障的代碼 
      <faultstring> 可供人閱讀的有關(guān)故障的說明 
      <faultactor> 有關(guān)是誰引發(fā)故障的信息 
      <detail> 存留涉及 Body 元素的應(yīng)用程序?qū)S缅e(cuò)誤信息 


      SOAP Fault 代碼 

      在下面定義的 faultcode 值必須用于描述錯(cuò)誤時(shí)的 faultcode 元素中: 
      VersionMismatch         SOAP Envelope 元素的無效命名空間被發(fā)現(xiàn) 
      MustUnderstand         Header 元素的一個(gè)直接子元素(帶有設(shè)置為 "1" 的 mustUnderstand 屬性)無法被理解。 
      Client         消息被不正確地構(gòu)成,或包含了不正確的信息。 
      Server         服務(wù)器有問題,因此無法處理進(jìn)行下去。 




      四、SOAP HTTP Binding 

      1,普通的HTTP協(xié)議 

      HTTP 在 TCP/IP 之上進(jìn)行通信。HTTP 客戶機(jī)使用 TCP 連接到 HTTP 服務(wù)器。在建立連接之后,客戶機(jī)可向服務(wù)器發(fā)送 HTTP 請(qǐng)求消息: 

      POST /item HTTP/1.1 
      Host: 189.123.345.239 
      Content-Type: text/plain 
      Content-Length: 200 

      隨后服務(wù)器會(huì)處理此請(qǐng)求,然后向客戶機(jī)發(fā)送一個(gè) HTTP 響應(yīng)。此響應(yīng)包含了可指示請(qǐng)求狀態(tài)的狀態(tài)代碼: 

      200 OK 
      Content-Type: text/plain 
      Content-Length: 200 

      在上面的例子中,服務(wù)器返回了一個(gè) 200 的狀態(tài)代碼。這是 HTTP 的標(biāo)準(zhǔn)成功代碼。 

      假如服務(wù)器無法對(duì)請(qǐng)求進(jìn)行解碼,它可能會(huì)返回類似這樣的信息: 

      400 Bad Request 
      Content-Length: 0 


      2,SOAP HTTP Binding 

      SOAP 方法指的是遵守 SOAP 編碼規(guī)則的 HTTP 請(qǐng)求/響應(yīng)。 

      HTTP + XML = SOAP 

      SOAP 請(qǐng)求可能是 HTTP POST 或 HTTP GET 請(qǐng)求。 

      HTTP POST 請(qǐng)求規(guī)定至少兩個(gè) HTTP 頭:Content-Type 和 Content-Length。 

      (1)Content-Type 
      SOAP 的請(qǐng)求和響應(yīng)的 Content-Type 頭可定義消息的 MIME 類型,以及用于請(qǐng)求或響應(yīng)的 XML 主體的字符編碼(可選)。 
      語法  Content-Type: MIMEType; charset=character-encoding 

      例子 
      POST /item HTTP/1.1 
      Content-Type: application/soap+xml; charset=utf-8 

      (2)Content-Length 
      SOAP 的請(qǐng)求和響應(yīng)的 Content-Length 頭規(guī)定請(qǐng)求或響應(yīng)主體的字節(jié)數(shù)。 
      語法  Content-Length: bytes 

      例子 
      POST /item HTTP/1.1 
      Content-Type: application/soap+xml; charset=utf-8 
      Content-Length: 250 



      五、一個(gè) SOAP 實(shí)例 

      在下面的例子中,一個(gè) GetStockPrice 請(qǐng)求被發(fā)送到了服務(wù)器。此請(qǐng)求有一個(gè) StockName 參數(shù),而在響應(yīng)中則會(huì)返回一個(gè) Price 參數(shù)。此功能的命名空間被定義在此地址中: "http://www./stock" 

      SOAP 請(qǐng)求: 

      POST /InStock HTTP/1.1 
      Host: www. 
      Content-Type: application/soap+xml; charset=utf-8 
      Content-Length: nnn 
      Xml代碼  收藏代碼
      1. <?xml version="1.0"?>  
      2. <soap:Envelope  
      3. xmlns:soap="http://www./2001/12/soap-envelope"  
      4. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      5.   
      6.   <soap:Body xmlns:m="http://www./stock">  
      7.     <m:GetStockPrice>  
      8.       <m:StockName>IBM</m:StockName>  
      9.     </m:GetStockPrice>  
      10.   </soap:Body>  
      11.     
      12. </soap:Envelope>  


      SOAP 響應(yīng): 

      HTTP/1.1 200 OK 
      Content-Type: application/soap+xml; charset=utf-8 
      Content-Length: nnn 
      Xml代碼  收藏代碼
      1. <?xml version="1.0"?>  
      2. <soap:Envelope  
      3. xmlns:soap="http://www./2001/12/soap-envelope"  
      4. soap:encodingStyle="http://www./2001/12/soap-encoding">  
      5.   
      6.   <soap:Body xmlns:m="http://www./stock">  
      7.     <m:GetStockPriceResponse>  
      8.       <m:Price>34.5</m:Price>  
      9.     </m:GetStockPriceResponse>  
      10.   </soap:Body>  
      11.     
      12. </soap:Envelope>  

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多