<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ricegun

    BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
      2 Posts :: 4 Stories :: 3 Comments :: 0 Trackbacks
    2009-05-11

    WSDL實(shí)例解析

    關(guān)鍵字: web service

    WSDL的主要文檔元素

    WSDL文檔可以分為兩部分。頂部分由抽象定義組成,而底部分則由具體描述組成。抽象部分以獨(dú)立于平臺(tái)和語(yǔ)言的方式定義SOAP消息,它們并不包含任何隨 機(jī)器或語(yǔ)言而變的元素。這就定義了一系列服務(wù),截然不同的應(yīng)用都可以實(shí)現(xiàn)。具體部分,如數(shù)據(jù)的序列化則歸入底部分,因?yàn)樗唧w的定義。在上述的文檔元 素中,<types>、<message>、<portType>屬于抽象定義 層,<binding>、<service>屬于具體定義層。所有的抽象可以是單獨(dú)存在于別的文件中,也可以從主文檔中導(dǎo)入。 

    WSDL文檔的結(jié)構(gòu)實(shí)例解析 
    下面我們將通過(guò)一個(gè)實(shí)際的WSDL文檔例子來(lái)詳細(xì)說(shuō)明各標(biāo)簽的作用及關(guān)系。

    Wsdl代碼 
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <definitions  
    3. xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  
    4. xmlns:tns="http://www.jsoso.com/wstest"  
    5. xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
    6. xmlns="http://schemas.xmlsoap.org/wsdl/"  
    7. targetNamespace="http://www.jsoso.com/wstest"  
    8. name="Example">  
    9. <types>  
    10. <xsd:schema>  
    11. <xsd:import  
    12. namespace="http://www.jsoso.com/wstest"  
    13. schemaLocation="http://localhost:8080/hello?xsd=1"></xsd:import>  
    14. </xsd:schema>  
    15. </types>  
    16. <message name="toSayHello">  
    17. <part name="userName" type="xsd:string"></part>  
    18. </message>  
    19. <message name="toSayHelloResponse">  
    20. <part name="returnWord" type="xsd:string"></part>  
    21. </message>  
    22. <message name="sayHello">  
    23. <part name="person" type="tns:person"></part>  
    24. <part name="arg1" type="xsd:string"></part>  
    25. </message>  
    26. <message name="sayHelloResponse">  
    27. <part name="personList" type="tns:personArray"></part>  
    28. </message>  
    29. <message name="HelloException">  
    30. <part name="fault" element="tns:HelloException"></part>  
    31. </message>  
    32. <portType name="Example">  
    33. <operation name="toSayHello" parameterOrder="userName">  
    34. <input message="tns:toSayHello"></input>  
    35. <output message="tns:toSayHelloResponse"></output>  
    36. </operation>  
    37. <operation name="sayHello" parameterOrder="person arg1">  
    38. <input message="tns:sayHello"></input>  
    39. <output message="tns:sayHelloResponse"></output>  
    40. <fault message="tns:HelloException" name="HelloException"></fault>  
    41. </operation>  
    42. </portType>  
    43. <binding name="ExamplePortBinding" type="tns:Example">  
    44. <soap:binding  
    45. transport="http://schemas.xmlsoap.org/soap/http"  
    46. style="rpc"></soap:binding>  
    47. <operation name="toSayHello">  
    48. <soap:operation soapAction="sayHello"></soap:operation>  
    49. <input>  
    50. <soap:body use="literal"  
    51. namespace="http://www.jsoso.com/wstest"></soap:body>  
    52. </input>  
    53. <output>  
    54. <soap:body use="literal"  
    55. namespace="http://www.jsoso.com/wstest"></soap:body>  
    56. </output>  
    57. </operation>  
    58. <operation name="sayHello">  
    59. <soap:operation soapAction="sayHello"></soap:operation>  
    60. <input>  
    61. <soap:body use="literal"  
    62. namespace="http://www.jsoso.com/wstest"></soap:body>  
    63. </input>  
    64. <output>  
    65. <soap:body use="literal"  
    66. namespace="http://www.jsoso.com/wstest"></soap:body>  
    67. </output>  
    68. <fault name="HelloException">  
    69. <soap:fault name="HelloException" use="literal"></soap:fault>  
    70. </fault>  
    71. </operation>  
    72. </binding>  
    73. <service name="Example">  
    74. <port name="ExamplePort" binding="tns:ExamplePortBinding">  
    75. <soap:address location="http://localhost:8080/hello"></soap:address>  
    76. </port>  
    77. </service>  
    78. </definitions>  

     

    由于上面的事例XML較長(zhǎng),我們將其逐段分解講解

     

    WSDL文檔的根元素:<definitions>

    Xml代碼 
    1. <definitions  
    2. xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  
    3. xmlns:tns="http://www.jsoso.com/wstest"  
    4. xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
    5. xmlns="http://schemas.xmlsoap.org/wsdl/"  
    6. targetNamespace="http://www.jsoso.com/wstest"  
    7. name="Example">  
    8. ……  
    9. ……  
    10. </definitions>  

     <definitions>定義了文檔中用到的各個(gè)xml元素的namespace縮寫(xiě),也界定了本文檔自己的 targetNamespace="http://www.jsoso.com/wstest",這意味著其它的XML要引用當(dāng)前XML中的元素時(shí),要聲 明這個(gè)namespace。注意xmlns:tns="http://www.jsoso.com/wstest"這個(gè)聲明,它標(biāo)示了使用tns這個(gè)前綴 指向自身的命名空間。

     

    WSDL文檔數(shù)據(jù)類(lèi)型定義元素:<types>

    Xml代碼 
    1. <types>  
    2. <xsd:schema>  
    3. <xsd:import  
    4. namespace="http://www.jsoso.com/wstest"  
    5. schemaLocation="http://localhost:8080/hello?xsd=1"></xsd:import>  
    6. </xsd:schema>  
    7. </types>  

     <types>標(biāo)簽定義了當(dāng)前的WSDL文檔用到的數(shù)據(jù)類(lèi)型。要說(shuō)明的是,為了最大程度的平臺(tái)中立性,WSDL 使用 XML Schema 語(yǔ)法來(lái)定義數(shù)據(jù)類(lèi)型。這些數(shù)據(jù)類(lèi)型用來(lái)定義web service方法的參數(shù)和返回指。對(duì)于通用的原生數(shù)據(jù)類(lèi)型如:integer , boolean , char , float等,在W3C的標(biāo)準(zhǔn)文檔http://www.w3.org/2001/XMLSchema中已經(jīng)做了定義。這里我們要引入的schema定義 schemaLocation="http://localhost:8080/hello?xsd=1"是我們自定義的Java對(duì)象類(lèi)型。

     

    WSDL文檔消息體定義元素:< message >

    Xml代碼 
    1. <message name="toSayHello">  
    2. <part name="userName" type="xsd:string"></part>  
    3. </message>  
    4. <message name="toSayHelloResponse">  
    5. <part name="returnWord" type="xsd:string"></part>  
    6. </message>  
    7. <message name="sayHello">  
    8. <part name="person" type="tns:person"></part>  
    9. <part name="arg1" type="xsd:string"></part>  
    10. </message>  
    11. <message name="sayHelloResponse">  
    12. <part name="personList" type="tns:personArray"></part>  
    13. </message>  
    14. <message name="HelloException">  
    15. <part name="fault" element="tns:HelloException"></part>  
    16. </message>  

     <message>元素定義了web service函數(shù)的參數(shù)。<message>元素中的每個(gè)<part>子元素都和某個(gè)參數(shù)相符。輸入?yún)?shù)在<message>元素中定義,與輸出參數(shù)相 隔離,輸出參數(shù)有自己的<message>元素。兼作輸入、輸出的參數(shù)在輸入輸出的<message>元素中有它們相應(yīng)的<part>元素。輸出 <message>元素以"Response"結(jié)尾,對(duì)Java而言方法得返回值就對(duì)應(yīng)一個(gè)輸出的<message>。每個(gè)<part>元素都有名字和類(lèi) 型屬性,就像函數(shù)的參數(shù)有參數(shù)名和參數(shù)類(lèi)型。 

    在上面的文檔中有兩個(gè)輸入?yún)?shù)、兩個(gè)輸出參數(shù)和一個(gè)錯(cuò)誤參數(shù)(對(duì)應(yīng)Java中的Exception)。 

    ? 輸入?yún)?shù)<message>的name屬性分別命名為toSayHello,sayHello。 
    toSayHello對(duì)應(yīng)輸入?yún)?shù)userName,參數(shù)類(lèi)型為xsd:string,在Java語(yǔ)言中就是String; 
    sayHello對(duì)應(yīng)兩個(gè)輸入?yún)?shù)person和arg1,類(lèi)型為tns:person和xsd:string。這里tns:person類(lèi)型就是引用了< types >標(biāo)簽中的類(lèi)型定義。 

    ? 輸出參數(shù)<message>的name屬性分別命名為toSayHelloResponse和sayHelloResponse。 
    這個(gè)名稱(chēng)和輸入?yún)?shù)的<message>標(biāo)簽name屬性對(duì)應(yīng),在其后面加上Response尾綴。 
    toSayHelloResponse對(duì)應(yīng)的返回值是returnWord,參數(shù)類(lèi)型為xsd:string; 
    sayHelloResponse對(duì)應(yīng)的返回值是personList,參數(shù)類(lèi)型為tns:personArray(自定義類(lèi)型); 

    ? 錯(cuò)誤參數(shù)<message>的name屬性為HelloException。 
    它的<part>子標(biāo)簽element而不是type來(lái)定義類(lèi)型。 

    以上的message標(biāo)簽的name屬性通常使用web service函數(shù)方法名作為參照,錯(cuò)誤參數(shù)標(biāo)簽則使用異常類(lèi)名為參照。標(biāo)簽中的參數(shù)名稱(chēng),即part子元素的name屬性是可自定義的(下一章節(jié)詳細(xì)說(shuō) 明)。message標(biāo)簽的參數(shù)類(lèi)型將引用types標(biāo)簽的定義。

     

    WSDL文檔函數(shù)體定義元素:< portType >

    Xml代碼 
    1. <portType name="Example">  
    2. <operation name="toSayHello" parameterOrder="userName">  
    3. <input message="tns:toSayHello"></input>  
    4. <output message="tns:toSayHelloResponse"></output>  
    5. </operation>  
    6. <operation name="sayHello" parameterOrder="person arg1">  
    7. <input message="tns:sayHello"></input>  
    8. <output message="tns:sayHelloResponse"></output>  
    9. <fault message="tns:HelloException" name="HelloException"></fault>  
    10. </operation>  
    11. </portType>  

     
    在<operation>元素中,name屬性表示服務(wù)方法名,parameterOrder屬性表示方法的參數(shù)順序,使用空格符分割多個(gè)參 數(shù),如:“parameterOrder="person arg1”。<operation>元素的子標(biāo)簽<input>表示輸入?yún)?shù)說(shuō)明,它引用<message>標(biāo)簽中的輸入?yún)?數(shù)。<output>表示輸出參數(shù)說(shuō)明,它引用<message>標(biāo)簽中的輸出參數(shù)。<fault>標(biāo)簽在Java方法中的特別 用來(lái)表示異常(其它語(yǔ)言有對(duì)應(yīng)的錯(cuò)誤處理機(jī)制),它引用<message>標(biāo)簽中的錯(cuò)誤參數(shù)。 

    WSDL綁定實(shí)現(xiàn)定義元素:< binding >

    Xml代碼 
    1. <binding name="ExamplePortBinding" type="tns:Example">  
    2. <soap:binding  
    3. transport="http://schemas.xmlsoap.org/soap/http"  
    4. style="rpc"></soap:binding>  
    5. <operation name="toSayHello">  
    6. <soap:operation soapAction="sayHello"></soap:operation>  
    7. <input>  
    8. <soap:body use="literal"  
    9. namespace="http://www.jsoso.com/wstest"></soap:body>  
    10. </input>  
    11. <output>  
    12. <soap:body use="literal"  
    13. namespace="http://www.jsoso.com/wstest"></soap:body>  
    14. </output>  
    15. </operation>  
    16. <operation name="sayHello">  
    17. <soap:operation soapAction="sayHello"></soap:operation>  
    18. <input>  
    19. <soap:body use="literal"  
    20. namespace="http://www.jsoso.com/wstest"></soap:body>  
    21. </input>  
    22. <output>  
    23. <soap:body use="literal"  
    24. namespace="http://www.jsoso.com/wstest"></soap:body>  
    25. </output>  
    26. <fault name="HelloException">  
    27. <soap:fault name="HelloException" use="literal"></soap:fault>  
    28. </fault>  
    29. </operation>  
    30. </binding>  

     <binding>標(biāo)簽是完整描述協(xié)議、序列化和編碼的地方,<types>,<message>和<portType>標(biāo)簽處理抽象的數(shù)據(jù)內(nèi)容,而<binding>標(biāo)簽是處理數(shù)據(jù)傳輸?shù)奈锢韺?shí)現(xiàn)。 
    <binding>標(biāo)簽把前三部分的抽象定義具體化。 

    首先<binding>標(biāo)簽使用<soap:binding>的transport和style屬性定義了Web Service的通訊協(xié)議HTTP和SOAP的請(qǐng)求風(fēng)格RPC。其次<operation>子標(biāo)簽將portType中定義的 operation同SOAP的請(qǐng)求綁定,定義了操作名稱(chēng)soapAction,輸出輸入?yún)?shù)和異常的編碼方式及命名空間。 

    WSDL服務(wù)地址綁定元素:< service >

    Xml代碼 
    1. <service name="Example">  
    2. <port name="ExamplePort" binding="tns:ExamplePortBinding">  
    3. <soap:address location="http://localhost:8080/hello"></soap:address>  
    4. </port>  
    5. </service>  

     service是一套<port>元素。在一一對(duì)應(yīng)形式下,每個(gè)<port>元素都和一個(gè)location關(guān)聯(lián)。如果同一個(gè)<binding>有多個(gè)<port>元素與之關(guān)聯(lián),可以使用額外的URL地址作為替換。 

    一個(gè)WSDL文檔中可以有多個(gè)<service>元素,而且多個(gè)<service>元素十分有用,其中之一就是可以根據(jù)目標(biāo)URL來(lái)組織端口。在一個(gè) WSDL文檔中,<service>的name屬性用來(lái)區(qū)分不同的service。在同一個(gè)service中,不同端口,使用端口的"name"屬性區(qū) 分。 

    簡(jiǎn)單的描述了WSDL對(duì)SOAP協(xié)議的支持,以及在Web Service中的作用。

    posted on 2010-08-11 16:06 第七日 閱讀(5277) 評(píng)論(1)  編輯  收藏

    Feedback

    # re: WSDL實(shí)例解析 2011-04-25 11:55 jay_hbb
    好  回復(fù)  更多評(píng)論
      


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 黄页免费视频播放在线播放| 免费毛片网站在线观看| 亚洲色欲色欱wwW在线| 日本高清免费网站| yy6080久久亚洲精品| 一级做a爰全过程免费视频毛片| 噜噜嘿在线视频免费观看| 亚洲免费视频在线观看| 久久久久久国产a免费观看不卡| 日本中文一区二区三区亚洲 | 日韩免费a级毛片无码a∨| 日韩免费电影网站| 91久久亚洲国产成人精品性色 | 国产亚洲精品一品区99热| 真实国产乱子伦精品免费| 亚洲精品无码av人在线观看| 亚洲色无码一区二区三区| 在线观看免费视频一区| a级毛片免费播放| 精品无码免费专区毛片| 亚洲av永久无码精品网址| 无码专区一va亚洲v专区在线| 国产成人无码a区在线观看视频免费| 国产高清在线免费| 国产精品亚洲美女久久久| 亚洲va中文字幕无码久久| 免费无码一区二区三区蜜桃大 | 亚洲国产日韩a在线播放| 黄网站色视频免费观看45分钟| 成人毛片100免费观看| 亚洲欧美日韩一区二区三区| 免费精品国自产拍在线播放| 亚洲欧美日本韩国| 久久国产精品萌白酱免费| 69天堂人成无码麻豆免费视频| 国产免费观看黄AV片| 精品日韩亚洲AV无码| 国产亚洲精品岁国产微拍精品| 亚洲午夜精品一区二区麻豆| caoporn国产精品免费| 国产又大又粗又硬又长免费|