经验demo

WSDL

2016-12-28  本文已影响95人  zlb

** 什么是 WSDL? **

** WSDL 可描述网络服务(Web Services)**

** WSDL文档结构 **

元素 定义
Types 数据类型定义的容器,它使用某种类型系统(一般地使用XML Schema中的类型系统)
Message 通信消息的数据结构的抽象类型化定义。使用Types所定义的类型来定义整个消息的数据结构
Operation 对服务中所支持的操作的抽象描述,一般单个Operation描述了一个访问入口的请求/响应消息对
PortType 对于某个访问入口点类型所支持的操作的抽象集合,这些操作可以由一个或多个服务访问点来支持
Binding 特定端口类型的具体协议和数据格式规范的绑定。
Service 相关服务访问点的集合

** WSDL文档 **

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.zlb.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWSService" targetNamespace="http://service.zlb.com/">
 <!-- types -->
  <wsdl:types>
    <!-- 定义 schema 约束   自己引用自己定义的约束 方便下面的应用  tns:命名 -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.zlb.com/" elementFormDefault="unqualified" targetNamespace="http://service.zlb.com/" version="1.0">
    <xs:element name="sayHello" type="tns:sayHello"/>
    <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
    <!-- 复合类型  -->
    <xs:complexType name="sayHello">  <!-- 方法名 -->
        <xs:sequence>
          <xs:element minOccurs="0" name="arg0" type="xs:string"/><!-- 参数 以及参数的类型 -->
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="sayHelloResponse">
        <xs:sequence>
          <xs:element minOccurs="0" name="return" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
  </wsdl:types>
  
  <!-- message -->
  <!-- 定义消息 -->
  <wsdl:message name="sayHelloResponse">  <!-- 响应消息 -->
    <wsdl:part element="tns:sayHelloResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>  
  <wsdl:message name="sayHello">  <!-- 请求消息 -->
    <wsdl:part element="tns:sayHello" name="parameters">
    </wsdl:part>
  </wsdl:message>
  
  <!-- portType -->
  <!-- 用来定义接口 -->
  <wsdl:portType name="helloWS">
    <wsdl:operation name="sayHello"> <!-- 用来指定处理请求的方法 -->
      <wsdl:input message="tns:sayHello" name="sayHello">  <!-- 指定客户端传过来的数据 引用上面定义的message -->
      </wsdl:input>
      <wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse">  <!-- 指定服务器端返回的数据 引用上面定义的message -->
      </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  
  <!-- wsdl:binding -->
  <!-- 用来定义实现类 -->
  <wsdl:binding name="HelloWSServiceSoapBinding" type="tns:helloWS"> <!-- type 引用上面的portType -->
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <!-- 指定样式为 XML格式的数据 -->
    <wsdl:operation name="sayHello"> <!-- operation 定义实现类的方法 -->
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="sayHello">
        <soap:body use="literal"/>  <!-- 指定客户端传过来的数据  基于文本形式 -->
      </wsdl:input>
      <wsdl:output name="sayHelloResponse">
        <soap:body use="literal"/>  <!-- 指定服务器返回给客户端的数据  基于文本形式 -->
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  
  <!-- wsdl:service -->
  <!-- 发布出去 并指定地址 -->
  <wsdl:service name="HelloWSService">
    <wsdl:port binding="tns:HelloWSServiceSoapBinding" name="helloWSPort"><!-- 引用 binding -->
      <soap:address location="http://127.0.0.1:8989/WebServices_service/helloWS"/> <!-- 地址 -->
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

这个WSDL的结构需要按照从下面往上面的顺序看

WSDL相关文章:<a href="http://blog.csdn.net/etttttss/article/details/17303315">WSDL详解</a>

上一篇下一篇

猜你喜欢

热点阅读