Web Service描述語言 WSDL 詳解(2)--WSDL文件示例[轉]
2024-07-21 02:21:56
供稿:網友
讓我們來研究一下wsdl文件,看看它的結構,以及如何工作。請注意這是一個非常簡單的wsdl文檔實例。我們的意圖只是說明它最顯著的特征。以下的內容中包括更加詳細的討論。
<?xml version="1.0" encoding="utf-8" ?>
<definitions name="foosample"
targetnamespace="http://tempuri.org/wsdl/"
xmlns:wsdlns="http://tempuri.org/wsdl/"
xmlns:typens="http://tempuri.org/xsd"
xmlns:xsd="http://www.w3.org/2001/xmlschema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-extension"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetnamespace="http://tempuri.org/xsd"
xmlns="http://www.w3.org/2001/xmlschema"
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
elementformdefault="qualified" >
</schema>
</types>
<message name="simple.foo">
<part name="arg" type="xsd:int"/>
</message>
<message name="simple.fooresponse">
<part name="result" type="xsd:int"/>
</message>
<porttype name="simpleporttype">
<operation name="foo" parameterorder="arg" >
<input message="wsdlns:simple.foo"/>
<output message="wsdlns:simple.fooresponse"/>
</operation>
</porttype>
<binding name="simplebinding" type="wsdlns:simpleporttype">
<stk:binding preferredencoding="utf-8" />
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="foo">
<soap:operation soapaction="http://tempuri.org/action/simple.foo"/>
<input>
<soap:body use="encoded" namespace="http://tempuri.org/message/"
encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://tempuri.org/message/"
encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="foosampleservice">
<port name="simpleport" binding="wsdlns:simplebinding">
<soap:address location="http://carlos:8080/foosample/foosample.asp"/>
</port>
</service>
</definitions>
以下是該實例文檔的總述:稍后我將詳細討論每一部分的細節。
第一行申明該文檔是xml。盡管這并不是必需的,但它有助于xml解析器決定是否解析wsdl文件或只是報錯。第二行是wsdl文檔的根元素:<definitions>。一些屬性附屬于根元素,就像<schema>子元素對于<types>元素。
<types>元素包含了types欄。如果沒有需要聲明的數據類型,這欄可以缺省。在wsdl范例中,沒有應用程序特定的types聲明,但我仍然使用了types欄,只是為了聲明schema namespaces。
<message>元素包含了messages欄。如果我們把操作看作函數,<message>元素定義了那個函數的參數。<message>元素中的每個<part>子元素都和某個參數相符。輸入參數在<message>元素中定義,與輸出參數相隔離--輸出參數有自己的<message>元素。兼作輸入、輸出的參數在輸入輸出的<message>元素中有它們相應的<part>元素。輸出<message>元素以"response"結尾,就像以前所用的"fooresponse"。每個<part>元素都有名字和類型屬性,就像函數的參數有參數名和參數類型。
用于交換文檔時,wsdl允許使用<message>元素來描述交換的文檔。
<part>元素的類型可以是xsd基類型,也可以是soap定義類型(soapenc)、wsdl定義類型(wsdl)或是types欄定義的類型。
一個porttypes欄中,可以有零個、單個或多個<porttype>元素。由于抽象porttype定義可以放置在分開的文件中,在某個wsdl文件中沒有<porttype>元素是可能的。上面的例子里只是用了一個<porttype>元素。而一個<porttype>元素可在<operation>元素中定義一個或是多個操作。示例僅使用了一個名為"foo"的<operation>元素。這和某個函數名相同。<operation>元素可以有一個、兩個、三個子元素:<input>, <output> 和<fault>元素。每個<input>和<output>元素中的消息都引用message欄中的相關的<message>元素。這樣,示例中的整個<porttype>元素就和以下的c函數等效:
int foo(int arg);
這個例子足見xml和c相比要冗長的多。(包括<message>元素,xml在示例中共使用了12行代碼來表達相同的單行函數聲明。)
bindings欄可以有零個、一個或者多個<binding>元素。它的意圖是制定每個<operation>通過網絡調用和回應。services欄同樣可以有零個、一個、多個<service>元素。它還包含了<port>元素,每個<port>元素引用一個bindings欄里的<binding>元素。bindings和services欄都包含wsdl文檔。
原文地址:http://www.yesky.com/20011013/200759_1.shtml