webservice之WSDL资料详解

转:http://www.educity.cn/wenda/144703.html

 

webservice之WSDL文件详解

  WSDL: Web Services Description Language 网页服务描述语言

  详解WSDL文档元素:

  文件是以XML格式定义的,内容分成了5大元素:

  1、<types>:webservice使用的数据类型,它是独立以机器和语言的类型定义,这些数据类型被<message>标签所使用。

  2、<message>:webservice使用的消息,它定义了webservice函数的参数。在webservice中输入参数和输出参数需要分开定义,使用不同的message标签体。message定义的输入输出参数,被<portType>标签使用。

  3、<portType>:webservice执行操作。该标签引用<message>标签定义的函数来描述函数的签名(操作名、输入参数、输出参数)

  4、<binding>:webservice通信协议。在portType中定义的每一项操作,都在此绑定中实现。

  5、<service>:该标签定义每一绑定的端口地址。

  WSDL文档可以分为两部分。顶部分由抽象定义组成,而底部分则由具体描述组成。抽象部分以独立于平台和语言的方式定义SOAP消息,它们并不包含任何随机器或语言而变的元素。这就定义了一系列服务,截然不同的应用都可以实现。具体部分,如数据的序列化则归入底部分,因为它包含具体的定义。在上述的文档元素中,<types>、<message>、<portType>属于抽象定义层,<binding>、<service>属于具体定义层。所有的抽象可以是单独存在于别的文件中,也可以从主文档中导入。

  WSDL文档一个实例:

  < xml version="1.0" encoding="UTF-8" > <wsdl:definitions xmlns:wsdl="" xmlns:ns1="" xmlns:ns="" xmlns:wsaw="" xmlns:http="" xmlns:ax21="" xmlns:xs="" xmlns:mime="" xmlns:soap="" xmlns:soap12="" targetNamespace=""> <wsdl:documentation>Library</wsdl:documentation> <wsdl:types> <xs:schema xmlns:ax22="" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace=""> <xs:import namespace="" /> <xs:element name="returnBook"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="isbn" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="Exception"> <xs:sequence> <xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType" /> </xs:sequence> </xs:complexType> <xs:element name="register"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="userName" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="passWord" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="registerResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:boolean" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="login"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="userName" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="passWord" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="loginResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:boolean" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="listLendBookResponse"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax22:Book" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="listAvailableBookResponse"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax22:Book" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="listAllBookResponse"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax22:Book" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="lendBook"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="isbn" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="userName" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="lendBookResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="return" nillable="true" type="ax22:Book" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace=""> <xs:complexType name="Book"> <xs:sequence> <xs:element minOccurs="0" name="author" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="isbn" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="title" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="loginRequest"> <wsdl:part name="parameters" element="ns:login" /> </wsdl:message> <wsdl:message name="loginResponse"> <wsdl:part name="parameters" element="ns:loginResponse" /> </wsdl:message> <wsdl:message name="lendBookRequest"> <wsdl:part name="parameters" element="ns:lendBook" /> </wsdl:message> <wsdl:message name="lendBookResponse"> <wsdl:part name="parameters" element="ns:lendBookResponse" /> </wsdl:message> <wsdl:message name="listAllBookRequest" /> <wsdl:message name="listAllBookResponse"> <wsdl:part name="parameters" element="ns:listAllBookResponse" /> </wsdl:message> <wsdl:message name="listLendBookRequest" /> <wsdl:message name="listLendBookResponse"> <wsdl:part name="parameters" element="ns:listLendBookResponse" /> </wsdl:message> <wsdl:message name="returnBookRequest"> <wsdl:part name="parameters" element="ns:returnBook" /> </wsdl:message> <wsdl:message name="registerRequest"> <wsdl:part name="parameters" element="ns:register" /> </wsdl:message> <wsdl:message name="registerResponse"> <wsdl:part name="parameters" element="ns:registerResponse" /> </wsdl:message> <wsdl:message name="listAvailableBookRequest" /> <wsdl:message name="listAvailableBookResponse"> <wsdl:part name="parameters" element="ns:listAvailableBookResponse" /> </wsdl:message> <wsdl:portType name="LibraryPortType"> <wsdl:operation name="login"> <wsdl:input message="ns:loginRequest" wsaw:Action="urn:login" /> <wsdl:output message="ns:loginResponse" wsaw:Action="urn:loginResponse" /> </wsdl:operation> <wsdl:operation name="lendBook"> <wsdl:input message="ns:lendBookRequest" wsaw:Action="urn:lendBook" /> <wsdl:output message="ns:lendBookResponse" wsaw:Action="urn:lendBookResponse" /> </wsdl:operation> <wsdl:operation name="listAllBook"> <wsdl:input message="ns:listAllBookRequest" wsaw:Action="urn:listAllBook" /> <wsdl:output message="ns:listAllBookResponse" wsaw:Action="urn:listAllBookResponse" /> </wsdl:operation> <wsdl:operation name="listLendBook"> <wsdl:input message="ns:listLendBookRequest" wsaw:Action="urn:listLendBook" /> <wsdl:output message="ns:listLendBookResponse" wsaw:Action="urn:listLendBookResponse" /> </wsdl:operation> <wsdl:operation name="returnBook"> <wsdl:input message="ns:returnBookRequest" wsaw:Action="urn:returnBook" /> </wsdl:operation> <wsdl:operation name="register"> <wsdl:input message="ns:registerRequest" wsaw:Action="urn:register" /> <wsdl:output message="ns:registerResponse" wsaw:Action="urn:registerResponse" /> </wsdl:operation> <wsdl:operation name="listAvailableBook"> <wsdl:input message="ns:listAvailableBookRequest" wsaw:Action="urn:listAvailableBook" /> <wsdl:output message="ns:listAvailableBookResponse" wsaw:Action="urn:listAvailableBookResponse" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="LibrarySoap11Binding" type="ns:LibraryPortType"> <soap:binding transport="" /> <wsdl:operation name="login"> <soap:operation soapAction="urn:login" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="lendBook"> <soap:operation soapAction="urn:lendBook" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="register"> <soap:operation soapAction="urn:register" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="listAllBook"> <soap:operation soapAction="urn:listAllBook" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="returnBook"> <soap:operation soapAction="urn:returnBook" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> </wsdl:operation> <wsdl:operation name="listLendBook"> <soap:operation soapAction="urn:listLendBook" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="listAvailableBook"> <soap:operation soapAction="urn:listAvailableBook" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="LibrarySoap12Binding" type="ns:LibraryPortType"> <soap12:binding transport="" /> <wsdl:operation name="login"> <soap12:operation soapAction="urn:login" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="lendBook"> <soap12:operation soapAction="urn:lendBook" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="register"> <soap12:operation soapAction="urn:register" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="listAllBook"> <soap12:operation soapAction="urn:listAllBook" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="returnBook"> <soap12:operation soapAction="urn:returnBook" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> </wsdl:operation> <wsdl:operation name="listLendBook"> <soap12:operation soapAction="urn:listLendBook" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="listAvailableBook"> <soap12:operation soapAction="urn:listAvailableBook" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="LibraryHttpBinding" type="ns:LibraryPortType"> <http:binding verb="POST" /> <wsdl:operation name="login"> <http:operation location="Library/login" /> <wsdl:input> <mime:content type="text/xml" part="login" /> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="login" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="lendBook"> <http:operation location="Library/lendBook" /> <wsdl:input> <mime:content type="text/xml" part="lendBook" /> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="lendBook" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="register"> <http:operation location="Library/register" /> <wsdl:input> <mime:content type="text/xml" part="register" /> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="register" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="listAllBook"> <http:operation location="Library/listAllBook" /> <wsdl:input> <mime:content type="text/xml" part="listAllBook" /> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="listAllBook" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="returnBook"> <http:operation location="Library/returnBook" /> <wsdl:input> <mime:content type="text/xml" part="returnBook" /> </wsdl:input> </wsdl:operation> <wsdl:operation name="listLendBook"> <http:operation location="Library/listLendBook" /> <wsdl:input> <mime:content type="text/xml" part="listLendBook" /> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="listLendBook" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="listAvailableBook"> <http:operation location="Library/listAvailableBook" /> <wsdl:input> <mime:content type="text/xml" part="listAvailableBook" /> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="listAvailableBook" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="Library"> <wsdl:port name="LibraryHttpSoap11Endpoint" binding="ns:LibrarySoap11Binding"> <soap:address location="" /> </wsdl:port> <wsdl:port name="LibraryHttpSoap12Endpoint" binding="ns:LibrarySoap12Binding"> <soap12:address location="" /> </wsdl:port> <wsdl:port name="LibraryHttpEndpoint" binding="ns:LibraryHttpBinding"> <http:address location="" /> </wsdl:port> </wsdl:service> </wsdl:definitions>

  理解这个WSDL文件结构可能要根据写的webservice程序结构来理解:

  280x495

  下面标红的地方都是元素之间引用的关系。

  1.WSDL文档的根元素:

  <wsdl:definitions xmlns:wsdl=""

  xmlns:ns1=""

  xmlns:ns=""

  xmlns:wsaw=""

  xmlns:http=""

  xmlns:ax21=""

  xmlns:xs=""

  xmlns:mime=""

  xmlns:soap=""

  xmlns:soap12=""

  targetNamespace="">

  <definitions>定义了文档中用到的各个xml元素的namespace缩写,也界定了本文档自己的 targetNamespace="",这意味着其它的XML要引用当前XML中的元素时,要声明这个namespace。注意xmlns:ns=""这个声明,它标示了使用ns这个前缀指向自身的命名空间。

  2.WSDL文档数据类型定义元素:<types>:

  <wsdl:types>

  <xs:schema xmlns:ax22=""

  attributeFormDefault="qualified" elementFormDefault="qualified"

  targetNamespace="">

  <xs:import namespace="" />

  <xs:element name="returnBook">

  <xs:complexType>

  <xs:sequence>

  <xs:element minOccurs="0" name="isbn" nillable="true"

  type="xs:string" />

  </xs:sequence>

  </xs:complexType>

  </xs:element>

  <xs:element name="login"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="userName" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="passWord" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="loginResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:boolean" /> </xs:sequence> </xs:complexType> </xs:element>

  这里定义webservice的一个元素名称returnBook,就是service的一个函数名称(见图),定义了混合类型数据类型,类型是string类型,名称叫isbn

  3.WSDL文档消息体定义元素:< message >:

  <wsdl:message name="loginRequest">

  <wsdl:part name="parameters" element="ns:login" />

  </wsdl:message>

  <wsdl:message name="loginResponse">

  <wsdl:part name="parameters" element="ns:loginResponse" />

  </wsdl:message>

  这里定义定义了消息请求,这里定义使用的消息是loginRequest和loginResponse,它分别引用了types中的login和loginResponse元素。在types中的login和loginResponse元素定义好了参数类型。有没有Response消息,主要是看你的函数是否有返回值,如果是void,想returnBook这函数就没有returnBookResponse。

  4.WSDL文档操作定义元素:< portType >

  <wsdl:portType name="LibraryPortType">

  <wsdl:operation name="login">

  <wsdl:input message="ns:loginRequest" wsaw:Action="urn:login" />

  <wsdl:output message="ns:loginResponse" wsaw:Action="urn:loginResponse" />

  </wsdl:operation>

  定义了操作名称login,输入使用的消息是loginRequest,Action是urn:login,输出ns:loginResponse,Action是:urn:loginResponse

  5、WSDL文档操作绑定协议<binding>:

  <wsdl:binding name="LibrarySoap11Binding" type="ns:LibraryPortType"> <soap:binding transport="" /> <wsdl:operation name="login"> <soap:operation soapAction="urn:login" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation>

  首先<binding>标签使用<soap:binding>的transport和style属性定义了Web Service的通讯协议HTTP和SOAP的请求风格RPC。其次<operation>子标签将portType中定义的 operation同SOAP的请求绑定,定义了操作名称soapAction,输出输入参数和异常的编码方式及命名空间。

  如果客户端要调用这方法就要声明是这soapAction名称urn:login。

  6、WSDL文档绑定服务端口地址<service>:

  <wsdl:service name="Library"> <wsdl:port name="LibraryHttpSoap11Endpoint" binding="ns:LibrarySoap11Binding"> <soap:address location="" /> </wsdl:port> <wsdl:port name="LibraryHttpSoap12Endpoint" binding="ns:LibrarySoap12Binding"> <soap12:address location="" /> </wsdl:port> <wsdl:port name="LibraryHttpEndpoint" binding="ns:LibraryHttpBinding"> <http:address location="" /> </wsdl:port> </wsdl:service>

  这里描述webservice的服务名称是Library,service是一套<port>元素。在一一对应形式下,每个<port>元素都和一个location关联。如果同一个<binding>有多个<port>元素与之关联,可以使用额外的URL地址作为替换。

  
一个WSDL文档中可以有多个<service>元素,而且多个<service>元素十分有用,其中之一就是可以根据目标URL来组织端口。在一个 WSDL文档中,<service>的name属性用来区分不同的service。在同一个service中,不同端口,使用端口的"name"属性区分。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Web服务描述语言(WSDL)是一种用于描述Web服务的XML格式文件。通过调用WSDL,我们可以访问和使用其他系统或应用程序中提供的Web服务。 使用Web服务调用语言(Web Services Description Language, WSDL),我们可以完成以下步骤来调用WSDL: 1. 首先,我们需要获取WSDL文件的URL或文件路径。通常,这是由Web服务的提供者提供的,他们会告诉我们WSDL文件的位置。 2. 一旦我们获取到WSDL文件,我们可以使用支持SOAP(Simple Object Access Protocol,简单对象访问协议)的编程语言来解析和使用WSDL。我们可以使用各种编程语言,如Java、.NET、Python等。 3. 我们需要在我们的代码中使用适当的库或框架来处理SOAP消息和WSDL定义的操作。 4. 我们需要创建一个SOAP请求消息,并将其发送到Web服务的提供者。请求消息将根据WSDL定义的操作和参数进行构建。 5. Web服务提供者将根据接收到的请求消息执行相应的操作,并返回响应消息。该响应消息将包含所请求操作的结果或错误信息。 6. 我们可以在我们的代码中解析和处理响应消息,并根据需要采取适当的操作。 总结来说,通过使用WSDL,我们可以了解有关特定Web服务的详细信息,包括操作、参数和消息结构。通过调用WSDL,我们可以构建和发送SOAP请求消息,并处理接收到的响应消息。这样,我们就可以与其他系统或应用程序之间实现交互,并获得所需的结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值