1.WSDL的定義
WSDL:Web Service Description Language。Web服務描述語言。用於描述web服務的技術調用語法。
2.WSDL的用途
簡單的講,WSDL向用戶解釋如何通過編程來調用這些服務。WSDLhi採用xml語言來描述web服務的屬性的文檔,其中包含web服務做什麼、位於哪裏、怎樣調用等信息。
3.WSDL文檔組成
WSDL文檔由5部分組成:
1. 類型部分(types):定義在web服務中使用了哪些數據類型以及從哪裏可以找到這些類型的定義。
2. 消息部分(messages):抽象的定義進入的和送出的消息。
3. 端口類型部分(portTypes):將協議和它支持的操作和操作使用的消息結合在一起。
4. 綁定部分(bindings):創建一種具有特定端口類型數據格式的具體關係的協議。
5. 服務部分(Service):將素有不同的端口及其具體位置集合在一起。
主要結構爲:
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
definition of a port.......
</portType>
<binding>
definition of a binding....
</binding>
<port>
definition of a port….
</port>
<service>
definition of a service….
</service>
</definitions>
其中type、message、portType爲抽象部分,binding、Port、Service爲具體部分。
4.WSDL文檔編寫的5個步驟
A. 聲明名稱空間
B. 編寫服務:即對portType的編寫
C. 指定參數,即對message的編寫
D. 與SOAP綁定,即對binding的編寫
E. 指定實現:即爲Service
5.實例
該實例是我在做“服務計算”這門課的一次作業中用到的。
問題描述:用WSDL描述代理業這項服務。
5.1用面向對象的方法分析代理業。
背景描述:委託人辦理受託事項的業務包括代購代銷貨物,代辦進口,介紹服務。其中代購代銷是指受託購買貨物或銷售貨物按實購或實銷額進行清算並收取手續費的業務。在此題中就把最簡單的代銷貨物作爲背景。即實現了代銷商在製造商和消費者之間搭線,商品通過製造商->代銷商->消費者。
分析:
由於面向對象是用封裝了數據和操作的對象以及對象之間的消息傳遞描述計算,所以在這個過程中,通過使用對象之間的通信來實現該功能。
在該問題中,有三方要實現通信:製造商、代銷商和消費者。代銷商通過受託購買貨物而收取手續費而獲得利益。
面向對象計算都是由一個團隊負責應用的開發,通過UML建模能夠更好的理解需求。
1) 類圖
該類圖中應用到了三個類:producer、Agent、Consumer。其中Agent和Consumer之間應用到了觀察者(Observer)模式,當Consumer調用toBuy()這個函數時,Agent就會偵聽到,於是Agent會在helpBuy()中通過Producer的實例producer調用sold()這個方法,sold()會返回Product類型的實例,最終將Product實例返回給Consumer
2) 2.2時序圖
該時序圖也清晰的展示了Consumer、Agent、Producer三者之間的信息傳遞關係:Consumer告訴Agent想要購買Product,於是Agent向Producer代替購買商品,Producer將商品返回給Agent,Agent最終將Product返回給Consumer。
5.2用WSDL描述代理服務
根據assignment2提交的作業,以代理業這項服務爲例,當服務請求者需要購買任何商品時能夠滿足。關於上次作業的類圖和時序圖,請參考最下面的“附錄”。
1.對命名空間的聲明
<?xml version="1.0" encoding="UTF-8"?>
<!--首先是對命名空間的聲明,包括三個必須做的外部名稱空間聲明WSDL、SOAP和XML模式-->
<wsdl:description
targetNamespace="http://loveharbor.net"
xmlns:wsdl="http://www.w3.org/ns/wsdl"
xmlns:wsoap="http://www.w3.org/ns/wsdl/soap"
xmlns:whttp="http://www.w3.org/ns/wsdl/http"
xmlns:xs=http://www.w3.org/2001/XMLSchema
xmlns:tns="http://new.webservice.namespace">
2.定義數據類型
<!--抽象部分-->
<wsdl:types><!--第一部分:定義數據類型-->
<xs:schematargetNamespace="http://loveharbor.net"elementFormDefault="qualified">
<!--這是對簡單的數據類型的定義,即爲消費者的狀態,是不是需要服務,是decimal簡單類型-->
<xs:element name="consumerState" type="xs:decimal"/>
<!--這裏定義的是產品Product的類型,是個複雜類型,其中包括狀態屬性productType,表示是否可以出售-->
<xs:element name="product">
<xs:complexType>
<xs:sequence>
<xs:element name="productType" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!--這是對返回的Product數組進行的定義,沒有得到解決-->
<xs:element name="returnProducts">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="soapenc:Array">
<xs:attribute ref="soapenc:arrayType"wsdl:arrayType="typens:product[]"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
3. 定義消息部分類型和端口類型。注:這裏是請求響應操作實例.同時包含input和output
<!--第二部分:定義消息部分類型和端口類型。注:這裏是請求響應操作實例.同時包含input和output-->
<wsdl:message name="getBuyRequest">
<wsdl:part name ="parameters" element = "tns:product"/>
</wsdl:message>
<wsdl:message name ="getBuyResponse">
<wsdl:part name = "parameters" element = "tns:returnProducts"/>
</wsdl:message>
<wsdl:portType name = "buyProductPorttype">
<wsdl:operation name="buy">
<wsdl:input name="getBuyRequest"messageLabel="wsdl:getBuyRequest"/>
<wsdl:outputname="getBuyResponse"messageLabel="wsdl:getBuyResponse"/> </wsdl:operation>
</wsdl:portType>
4.綁定部分
<wsdl:binding name="buyProductBinding" type="wsdl:buyProductPorttype">
<wsoap:binding style = "document" transport = "http://schhemas.xmlsoap.org/soap/http"/>
<wsdl:operation name ="helpBuyProduct">
<wsoap:operationsoapAction=""/>
<wsdl:input name="getBuyRequest">
<wsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getBuyResponse">
<wsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
5.服務部分
<wsdl:service name="buyProductService">
<wsdl:endpoint name="buyProduct" binding="wsdl:buyProductBinding"/>
</wsdl:service>
</wsdl:description>