WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,它可规定服务的位置,以及此服务提供的操作(或方法)。用于描述webservice 类型;客户端和服务之间的通信;传入消息和传出消息;端口类型;服务所在 URI 和协议绑定。(接口被绑定到确切的协议上, WSDL支持对SOAP 1.1、HTTP GET/POST 以及MIME 的绑定)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
< schema targetNamespace ="http://outlook.microsoft.com/add-ins/SMS/type" 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" />
</ types >
< message name ="SMSWebService.sendXml" >
< part name ="Carrier" type ="xsd:string" />
< part name ="Id" type ="xsd:string" />
< part name ="Password" type ="xsd:string" />
< part name ="ToMobile" type ="xsd:string" />
< part name ="Message" type ="xsd:string" />
< part name ="MsgType" type ="xsd:string" />
</ message >
< message name ="SMSWebService.sendXmlResponse" >
< part name ="Result" type ="xsd:string" />
</ message >
< portType name ="SMSWebServiceSoapPort" >
< operation name ="sendXml" parameterOrder ="Carrier Id Password ToMobile Message MsgType" >
< input message ="wsdlns:SMSWebService.sendXml" />
< output message ="wsdlns:SMSWebService.sendXmlResponse" />
</ operation >
</ portType >
< binding name ="SMSWebServiceSoapBinding" type ="wsdlns:SMSWebServiceSoapPort" >
< stk:binding preferredEncoding ="UTF-8" />
< soap:binding style ="rpc" transport ="http://schemas.xmlsoap.org/soap/http" />
< operation name ="sendXml" >
< soap:operation soapAction ="http://outlook.microsoft.com/add-ins/SMS/action/SMSWebService.sendXml" />
< input >
< soap:body use ="encoded" namespace ="http://outlook.microsoft.com/add-ins/SMS/message/" encodingStyle ="http://schemas.xmlsoap.org/soap/encoding/" />
</ input >
< output >
< soap:body use ="encoded" namespace ="http://outlook.microsoft.com/add-ins/SMS/message/" encodingStyle ="http://schemas.xmlsoap.org/soap/encoding/" />
</ output >
</ operation >
</ binding >
< service name ="SMSWS" >
< port name ="SMSWebServiceSoapPort" binding ="wsdlns:SMSWebServiceSoapBinding" >
< soap:address location ="http://202.108.35.168/cgi-bin/ws/smswebservice0101" />
</ port >
</ service >
这是一个发送短信的webservice定义的一部分。 它定义了一个名为sendXml的方法和相关的 SOAP 信息,该信息使一段代码可以查找服务、调用方法和处理响应。
WSDL 文档开头是一个说明性部分,列出了两个关键组件。第一个由各种命名空间声明组成,并声明为根元素的属性。第二个组件是可选的<types>元素,用于定义WSDL文档内将用到的具体数据类型。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
< definitions name ="SMSWS" targetNamespace ="http://outlook.microsoft.com/add-ins/SMS/wsdl/" xmlns:wsdlns ="http://outlook.microsoft.com/add-ins/SMS/wsdl/" xmlns:typens ="http://outlook.microsoft.com/add-ins/SMS/type" xmlns:soap ="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd ="http://www.w3.org/2001/XMLSchema" xmlns:stk ="http://schemas.microsoft.com/soap-toolkit/wsdl-extension" xmlns ="http://schemas.xmlsoap.org/wsdl/" >
< types >
......
</ types >
下面是 WSDL 文档的剩余部分,由两个 <message> 元素(一个请求,一个应答)、一个 <portType> 元素(包含一个单独的 <operation> 元素),一个 <binding> 元素(该元素进一步定义了 <operation> 元素),以及一个 <service> 元素组成。
<types> 元素定义 web service 使用的数据类型。为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型。
<message> 元素定义一个操作的数据元素。每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数。<portType> 元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。端口定义了指向某个 web service 的连接点。可以把 <portType> 元素比作传统编程语言中的一个函数库(或一个模块、或一个类)。
<binding> 元素为每个端口定义消息格式和协议细节。binding 元素有两个属性 - name 属性和 type 属性。name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口,在这个例子中是 "glossaryTerms" 端口。
soap:binding 元素有两个属性 - style 属性和 transport 属性。style 属性可取值 "rpc" 或 "document"。在这个例子中我们使用 rpc。transport 属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP。
operation 元素定义了每个端口提供的操作符。对于每个操作,相应的 SOAP 行为都需要被定义。同时必须如何对输入和输出进行编码。
操作类型:请求-响应是最普通的操作类型,不过 WSDL 定义了四种类型:One-way(此操作可接受消息,但不会返回响应),Request-response(此操作可接受一个请求并会返回一个响应),Solicit-response(此操作可发送一个请求,并会等待一个响应),Notification(此操作可发送一条消息,但不会等待响应)。