WSDL 指網(wǎng)絡(luò )服務(wù)描述語(yǔ)言 (Web Services Description Language)。一個(gè)WSDL文檔是一個(gè)服務(wù)的描述,它描述了:服務(wù)名,服務(wù)地址,服務(wù)能用什么協(xié)議訪(fǎng)問(wèn),服務(wù)有哪些方法,每個(gè)方法有幾部分參數,每個(gè)參數的類(lèi)型。
在一個(gè)WSDL文檔中,你最經(jīng)??吹降脑厍熬Y會(huì )有wsdl、soap、xsd。當然這些前綴是與命名空間URI對應的,前綴是可以自己定義的,或許與此不同,但大都這么定義。
WSDL在設計時(shí),充分考慮了,各個(gè)元素模塊的重用(好像一個(gè)類(lèi)中定義了一些方法,可被不同方法共同調用)如:wsdl:binding、wsdl:portType、wsdl:message,你定義的這個(gè)元素可能被幾個(gè)地方引用到。所以WSDL設計者把它設計的夠精簡(jiǎn)、靈活。
下面我基于WSDL 1.2 語(yǔ)法分別對三個(gè)命名空間的經(jīng)常用到的元素解釋一下:最好從下往上看
//文檔的根元素,表示這是一個(gè)服務(wù)的定義,在此定義中默認的名字空間URI為“http://axisversion.sample”.
<wsdl:definitions xmlns:axis2="http://axisversion.sample" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns0="http://axisversion.sample/xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://axisversion.sample">
<wsdl:documentation>
This service is to get the running Axis version
</wsdl:documentation>
//為它表示所有消息中能使用的基本元素類(lèi)型,如一個(gè)方法三個(gè)參數的其中一個(gè)參數的類(lèi)型。
<wsdl:types>
<xs:schema xmlns:ns="http://axisversion.sample/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://axisversion.sample/xsd">
//為了最大程度的平臺中立性,WSDL 使用 XML Schema 語(yǔ)法來(lái)定義數據類(lèi)型
<xs:element name="ExceptionFault">
<xs:complexType>
<xs:sequence>
<xs:element name="Exception" nillable="true" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getVersionResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
//這是定義一個(gè)消息,是一次服務(wù)調用的一個(gè)消息。也就是下面的方法可以用到(指定)的方法參數。
<wsdl:message name="getVersionMessage"/>
<wsdl:message name="getVersionResponse">
<wsdl:part name="part1" element="ns0:getVersionResponse"/>//這是這個(gè)消息的第一人部分,同方法的第一個(gè)參數
</wsdl:message>
<wsdl:message name="getVersionFault">
<wsdl:part name="part1" element="ns0:ExceptionFault"/>
</wsdl:message>
*//端口類(lèi)型,它表示被某種端口類(lèi)型(訪(fǎng)問(wèn)協(xié)議)指定的一組可被這個(gè)端口執行的操作,以及相關(guān)消息,你可以它理解為可被調用的一個(gè)函數庫。
<wsdl:portType name="VersionPortType">
//操作,它表示其中一個(gè)操作
<wsdl:operation name="getVersion">
//輸入,用它指定一個(gè)輸入消息
<wsdl:input xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" message="axis2:getVersionMessage" wsaw:Action="urn:getVersion"/>
//輸出,用它指定一個(gè)返回消息
<wsdl:output message="axis2:getVersionResponse"/>
//錯誤,用它指明發(fā)生錯誤時(shí),返回的消息
<wsdl:fault message="axis2:getVersionFault" name="getVersionFault"/>
</wsdl:operation>
</wsdl:portType>
//綁定,此元素詳細描述了某個(gè)端口,的消息傳輸協(xié)議和消息包裝格式。(用于服務(wù)器端收到消息中的解析)
<wsdl:binding name="VersionSOAP11Binding" type="axis2:VersionPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
//此處用于表示,當收到一個(gè)消息請求方法為“urn:getVersion”時(shí),用此元素包含的描述定義來(lái)解析此消息。并確定消息所請求的方法所對應的服務(wù)的方法“wsdl:operation name="getVersion”。 <wsdl:operation name="getVersion">
<soap:operation soapAction="urn:getVersion" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="getVersionFault">
<soap12:fault use="literal" name="getVersionFault"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
//SOAP:binding是采用SOAP1.1版本。soap12:binding是采用SOAP1.2版本, 并且是采用SOAP規范來(lái)形成HTTPRequest
<wsdl:binding name="VersionSOAP12Binding" type="axis2:VersionPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getVersion">
<soap12:operation soapAction="urn:getVersion" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="getVersionFault">
<soap12:fault use="literal" name="getVersionFault"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
//此binding 是采用HTTP規范來(lái)填寫(xiě)消息內容
<wsdl:binding name="VersionHttpBinding" type="axis2:VersionPortType">
<http:binding verb="POST"/>
<wsdl:operation name="getVersion">
<http:operation location="getVersion"/>
<wsdl:input>
<mime:content type="text/xml"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
//此元素用于描述一個(gè)服務(wù)定義中其中的一個(gè)服務(wù)(可定義多個(gè)服務(wù))。和此服務(wù)所有可訪(fǎng)問(wèn)的端口和訪(fǎng)問(wèn)地址
<wsdl:service name="Version">
<wsdl:port name="VersionSOAP11port_http" binding="axis2:VersionSOAP11Binding">
<soap:address location="http://192.9.107.58:8080/axis2/services/Version"/>
</wsdl:port>
<wsdl:port name="VersionSOAP12port_http" binding="axis2:VersionSOAP12Binding">
<soap12:address location="http://192.9.107.58:8080/axis2/services/Version"/>
</wsdl:port>
<wsdl:port name="VersionHttpport" binding="axis2:VersionHttpBinding">
<http:address location="http://192.9.107.58:8080/axis2/services/Version"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>