转 wsdl

来源:互联网 发布:医疗优化站不收录 编辑:程序博客网 时间:2024/04/29 05:19

 WSDL是web service标准当中描述语言,服务器端通过wsdl可以描述发布的服务,客户端通过获取服务端提供的wsdl了解服务器端,以便调用服务器端提供的服务。

元素

定义

<portType>

web service 执行的操作

<message>

web service 使用的消息

<types>

web service 使用的数据类型

<binding>

web service 使用的通信协议

<service>

web service 使用的服务名称和地址

      下面分段了解一下wsdl的详细描述吧。我们通过一个搜索方法来描述,该方法提供输入搜索字段和搜索关键字,分别是String类型的。返回结果是一个结果集,用List类型保存。我们按照上面的表格来一个个的分析下WSDL的构成。

      <service>元素描述

Xml代码  收藏代码
  1. <wsdl:service name="SimpleSearch_Server">  
  2.  <wsdl:port name="SimpleSearch_ServerHttpPort" binding="tns:SimpleSearch_ServerHttpBinding">  
  3.   <wsdlsoap:address location="http://localhost:8080/Patent_Demo/services/SimpleSearch_Server" />   
  4.  </wsdl:port>  
  5. </wsdl:service>  
 

 1.   申明该服务的名称是SimpleSearch_Server

 2.   Binding表示需要绑定的通信协议是什么,绑定到wsdl当中的binding元素,这里指定到SimpleSearch_ServerHttpBinding当中。

 3.   申明提供的服务地址是:

http://localhost:8080/Patent_Demo/services/SimpleSearch_Server通过访问

http://localhost:8080/Patent_Demo/services/SimpleSearch_Server?wsdl可以查看wsdl信息

 

 

<binding>元素描述

Xml代码  收藏代码
  1. <wsdl:binding name="SimpleSearch_ServerHttpBinding" type="tns:SimpleSearch_ServerPortType">  
  2.   <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />   
  3.      <wsdl:operation name="search">  
  4.        <wsdlsoap:operation soapAction="" />   
  5.           <wsdl:input name="searchRequest">  
  6.             <wsdlsoap:body use="literal" />   
  7.          </wsdl:input>  
  8.          <wsdl:output name="searchResponse">  
  9.             <wsdlsoap:body use="literal" />   
  10.         </wsdl:output>  
  11.      </wsdl:operation>  
  12.   </wsdl:binding>  
1.       申明该binding名称是SimpleSearch_ServerHttpBinding

2.       指定该binding指定的操作元素为tns:SimpleSearch_ServerPortType

3.       该服务提供search方法,并具有request-response模式。消息传递类型为literal

 

    <Port-type>元素描述

Xml代码  收藏代码
  1. <wsdl:portType name="SimpleSearch_ServerPortType">  
  2.     <wsdl:operation name="search">  
  3.         <wsdl:input name="searchRequest"                     message="tns:searchRequest" />   
  4.        <wsdl:output name="searchResponse" message="tns:searchResponse" />   
  5.    </wsdl:operation>  
  6.  </wsdl:portType>  
   1.       定义提供search方法

   2.       定义request-response模式,并制定消息类型为searchRequest和searchResponse

 

      <message>元素描述

Xml代码  收藏代码
  1. <wsdl:message name="searchResponse">  
  2.   <wsdl:part name="parameters" element="tns:searchResponse" />   
  3. </wsdl:message>  
  4. <wsdl:message name="searchRequest">  
  5.   <wsdl:part name="parameters" element="tns:search" />   
  6. </wsdl:message>  
    1.       对应port-type当中的消息类型,以searchResponse为例,当用户发送请求的时候,定义请求参数类型为search

    2.       searchResponse当中定义了当请求处理完毕向用户返回参数的类型为searchResponse。两者都对应到<type>元素当中

 

      <type>元素描述

    <wsdl:types>

Xml代码  收藏代码
  1.    
  2. <wsdl:types>  
  3. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.ws.patent.com">  
  4.  <xsd:element name="search">  
  5.  <xsd:complexType>  
  6.  <xsd:sequence>  
  7.   <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" />   
  8.   <xsd:element maxOccurs="1" minOccurs="1" name="in1" nillable="true" type="xsd:string" />   
  9.   </xsd:sequence>  
  10.   </xsd:complexType>  
  11.   </xsd:element>  
  12.  <xsd:complexType name="ArrayOfString">  
  13.  <xsd:sequence>  
  14.   <xsd:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type="xsd:string" />   
  15.   </xsd:sequence>  
  16.   </xsd:complexType>  
  17.  <xsd:element name="searchResponse">  
  18.  <xsd:complexType>  
  19.  <xsd:sequence>  
  20.   <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="tns:ArrayOfString" />   
  21.   </xsd:sequence>  
  22.   </xsd:complexType>  
  23.   </xsd:element>  
  24.   </xsd:schema>  
  25.   </wsdl:types>  
        1.       search类型对应message消息当中请求消息类型,searchResponse同样如此。

        2.       search当中定义请求的第0,1个参数分别用String类型表示

        3.       searchResponse中定义返回以几何形式(ArrayofString)类型。ArrayofString在type元素当中也有定义,表示由String组成的类型组成

 

 

0 0
原创粉丝点击