【转】WebServices:WSDL的结构分析
????? WSDL(Web Services Description Language,Web服務(wù)描述語(yǔ)言)是為描述Web Services發(fā)布的XML格式。W3C組織沒(méi)有批準(zhǔn)1.1版的WSDL,但是2.0版本已經(jīng)在製訂中,2.0版將被作為推薦標(biāo)準(zhǔn)(recommendation)(一種官方標(biāo)準(zhǔn)),并將被W3C組織批準(zhǔn)為正式標(biāo)準(zhǔn)。WSDL描述Web服務(wù)的公共接口。這是一個(gè)基于XML的關(guān)于如何與Web服務(wù)通訊和使用的服務(wù)描述;也就是描述與目錄中列出的Web服務(wù)進(jìn)行交互時(shí)需要綁定的協(xié)議和信息格式。通常采用抽象語(yǔ)言描述該服務(wù)支持的操作和信息,使用的時(shí)候再將實(shí)際的網(wǎng)絡(luò)協(xié)議和信息格式綁定給該服務(wù)。
????? WSDL 文檔僅僅是一個(gè)簡(jiǎn)單的 XML 文檔。它包含一系列描述某個(gè) web service 的定義。
????? WebMthod的定義:
1: [WebService(Namespace = "http://tempuri.org/")] 2: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 3: [System.ComponentModel.ToolboxItem(false)] 4: public class WebService2 : System.Web.Services.WebService 5: { 6: [WebMethod] 7: public bool Add(TestClass testClass,int id) 8: { 9: return true; 10: } 11: } 12: ? 13: public class TestClass 14: { 15: public int a; 16: public string b; 17: public DateTime c; 18: } 19: ??????? WSDL的結(jié)構(gòu):
?????? 一個(gè)WSDL文檔通常包含有以下元素,即types、message、portType、operation、binding、 service元素。這些元素嵌套在definitions元素中。
??????definitions是WSDL文檔的根元素,definitions還聲明各命名空間。
??????types,數(shù)據(jù)類型定義的容器,它使用某種類型系統(tǒng)(一般地使用XML Schema中的類型系統(tǒng))。
1: <wsdl:types> 2: <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> 3: <s:element name="Add"> 4: <s:complexType> 5: <s:sequence> 6: <s:element minOccurs="0" maxOccurs="1" name="testClass" type="tns:TestClass" /> 7: <s:element minOccurs="1" maxOccurs="1" name="id" type="s:int" /> 8: </s:sequence> 9: </s:complexType> 10: </s:element> 11: <s:complexType name="TestClass"> 12: <s:sequence> 13: <s:element minOccurs="1" maxOccurs="1" name="a" type="s:int" /> 14: <s:element minOccurs="0" maxOccurs="1" name="b" type="s:string" /> 15: <s:element minOccurs="1" maxOccurs="1" name="c" type="s:dateTime" /> 16: </s:sequence> 17: </s:complexType> 18: <s:element name="AddResponse"> 19: <s:complexType> 20: <s:sequence> 21: <s:element minOccurs="1" maxOccurs="1" name="AddResult" type="s:boolean" /> 22: </s:sequence> 23: </s:complexType> 24: </s:element> 25: </s:schema> 26: </wsdl:types>???? types描述WebMethod的名稱(Add),傳入?yún)?shù)(testClass——包括對(duì)TestClass的詳細(xì)描述,id),響應(yīng)信息(AddResponse)。
?????message描述通信消息的數(shù)據(jù)結(jié)構(gòu)的抽象類型化定義,使用types的描述的類型來(lái)定義整個(gè)消息的數(shù)據(jù)結(jié)構(gòu)。
1: <wsdl:message name="AddSoapIn"> 2: <wsdl:part name="parameters" element="tns:Add" /> 3: </wsdl:message> 4: <wsdl:message name="AddSoapOut"> 5: <wsdl:part name="parameters" element="tns:AddResponse" /> 6: </wsdl:message>??????portType和operation描述服務(wù)和服務(wù)的方法。operation包括輸入和輸出(使用message的描述)。
1: <wsdl:portType name="WebService2Soap"> 2: <wsdl:operation name="Add"> 3: <wsdl:input message="tns:AddSoapIn" /> 4: <wsdl:output message="tns:AddSoapOut" /> 5: </wsdl:operation> 6: </wsdl:portType>???????binding描述Web Services的通信協(xié)議。 <soap:binding/>描述使用SOAP協(xié)議,binding還描述Web Services的方法、輸入、輸出。
1: <wsdl:binding name="WebService2Soap" type="tns:WebService2Soap"> 2: <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 3: <wsdl:operation name="Add"> 4: <soap:operation soapAction="http://tempuri.org/Add" style="document" /> 5: <wsdl:input> 6: <soap:body use="literal" /> 7: </wsdl:input> 8: <wsdl:output> 9: <soap:body use="literal" /> 10: </wsdl:output> 11: </wsdl:operation> 12: </wsdl:binding>???????service描述Web Services訪問(wèn)點(diǎn)的集合。因?yàn)榘⊿OAP1.1和SOAP1.2的描述,所以一個(gè)方法有對(duì)應(yīng)兩描述。
1: <wsdl:service name="WebService2"> 2: <wsdl:port name="WebService2Soap" binding="tns:WebService2Soap"> 3: <soap:address location="http://localhost:1552/WebService2.asmx" /> 4: </wsdl:port> 5: <wsdl:port name="WebService2Soap12" binding="tns:WebService2Soap12"> 6: <soap12:address location="http://localhost:1552/WebService2.asmx" /> 7: </wsdl:port> 8: </wsdl:service>總結(jié)
以上是生活随笔為你收集整理的【转】WebServices:WSDL的结构分析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 曾经世界第一 被黑最狠的IE浏览器:终于
- 下一篇: 177万!全球首款太阳能电动车量产在即: