Web 服務描述語言(Web Services Description Language,WSDL)提供了一種描述 Web 服務(大多使用 SOAP)的簡單方法。WSDL 允許您描述利用 SOAP 標准所提供的服務和接口。
比方說,可以創建描述某台服務器上提供的服務的 WSDL 文件,然後把該文件分發給需要這些服務的 Web 服務消費者。通過閱讀和解析 WSDL 文件,消費者能夠了解到使用這些 Web 服務需要知道的所有信息,包括可以交換的數據類型、參數以及返回的各種錯誤和其他信息。
再次使用來自 W3C 的例子,可以看到不同遠程函數的聲明和交換的數據都是通過結構的 XML 定義處理的,如清單 3 所示。
清單 3. 不同遠程函數和交換數據的 XML 定義
?xml version=1.0?! root element wsdl:definitions defines set of related services wsdl:definitions name=EndorsementSearchtargetNamespace=http://namespaces.snowboard-info.comxmlns:es=http://www.snowboard-info.com/EndorsementSearch.wsdlxmlns:esxsd=http://schemas.snowboard-info.com/EndorsementSearch.xsdxmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/xmlns:wsdl=http://schemas.xmlsoap.org/wsdl/! wsdl:types encapsulates schema definitions of communication types;here using xsd wsdl:types! all type declarations are in a chunk of xsd xsd:schema targetNamespace=http://namespaces.snowboard-info.comxmlns:xsd=http://www.w3.org/1999/XMLSchema! xsd definition: GetEndorsingBoarder [manufacturer string, model string] xsd:element name=GetEndorsingBoarderxsd:complexTypexsd:sequencexsd:element name=manufacturer type=string/xsd:element name=model type=string//xsd:sequence/xsd:complexType/xsd:element! xsd definition: GetEndorsingBoarderResponse [... endorsingBoarder string ...] xsd:element name=GetEndorsingBoarderResponsexsd:complexTypexsd:allxsd:element name=endorsingBoarder type=string//xsd:all/xsd:complexType/xsd:element! xsd definition: GetEndorsingBoarderFault [... errorMessage string ...] xsd:element name=GetEndorsingBoarderFaultxsd:complexTypexsd:allxsd:element name=errorMessage type=string//xsd:all/xsd:complexType/xsd:element/xsd:schema/wsdl:types! wsdl:message elements describe potential transactions ! request GetEndorsingBoarderRequest is of type GetEndorsingBoarder wsdl:message name=GetEndorsingBoarderRequestwsdl:part name=body element=esxsd:GetEndorsingBoarder//wsdl:message! response GetEndorsingBoarderResponse is of typeGetEndorsingBoarderResponse wsdl:message name=GetEndorsingBoarderResponsewsdl:part name=body element=esxsd:GetEndorsingBoarderResponse//wsdl:message! wsdl:portType describes messages in an operation wsdl:portType name=GetEndorsingBoarderPortType! the value of wsdl:operation eludes me wsdl:operation name=GetEndorsingBoarderwsdl:input message=es:GetEndorsingBoarderRequest/wsdl:output message=es:GetEndorsingBoarderResponse/wsdl:fault message=es:GetEndorsingBoarderFault//wsdl:Operation/wsdl:portType! wsdl:binding states a serialization protocol for this service wsdl:binding name=EndorsementSearchSoapBindingtype=es:GetEndorsingBoarderPortType! leverage off soap:binding document style ...(no wsdl:foo pointing at the soap binding) soap:binding style=documenttransport=http://schemas.XMLsoap.org/soap/http/! semi-opaque container of network transport details classed by soap:binding above ... wsdl:operation name=GetEndorsingBoarder! again bind to SOAP? ... soap:operation soapAction=http://www.snowboard-info.com/EndorsementSearch/! further specify that the messages in the wsdl:operation GetEndorsingBoarder use SOAP? ... wsdl:inputsoap:body use=literal namespace=http://schemas.snowboard-info.com/EndorsementSearch.xsd//wsdl:inputwsdl:outputsoap:body use=literal namespace=http://schemas.snowboard-info.com/EndorsementSearch.xsd//wsdl:outputwsdl:faultsoap:body use=literal namespace=http://schemas.snowboard-info.com/EndorsementSearch.xsd//wsdl:fault/wsdl:Operation/wsdl:binding! wsdl:service names a new service EndorsementSearchService wsdl:service name=EndorsementSearchServicewsdl:documentationsnowboarding-info.com Endorsement Service/wsdl:documentation ! connect it to the binding EndorsementSearchSoapBinding above wsdl:port name=GetEndorsingBoarderPort binding=es:EndorsementSearchSoapBinding! give the binding an network address soap:address location=http://www.snowboard-info.com/EndorsementSearch//wsdl:port/wsdl:service /wsdl:definitions
WSDL 聲明了消息類型、默認數據類型和內容以及交換的數據結構。
服務器上 SOAP 結構需要使用的一切信息都可以在這個 WSDL 中找到。大多數語言和環境都提供一種閱讀和解析 WSDL 的機制,以確定可用的函數和數據交換。
WSDL 不僅定義了用於交換信息的 SOAP 接口,通過適當的 WSDL 生成程序,還可用於創建發送請求、生成並格式化響應所需要的代碼。
WSDL 和 SOAP 組成了一個強大的遠程過程調用系統。