分析WSDL 的构成

来源:互联网 发布:家用电脑主机 知乎 编辑:程序博客网 时间:2024/05/01 23:16

分析WSDL 的构成:


下面我们来解释一下你所看到的WSDL 的结构,你可以对照你所生成WSDL(文件太长,Word 里实在放不下)

(1.)<wsdl:definitions …

   这个是WSDL 的根元素,我们要关心的是三个属性,name 属性值为公开的Web 服务的接
口的实现类+Service(上例中为name="HelloServiceImplService",不同的JAX-WS
实现名字是不一样的 );

targetNamespace 指定目标名称空间,targetNamespace 的值被后面的xmlns:tns 属性作为值, 默认是使用接口实现类的包名的反缀

targetNamespace="http://server.soap.ilkj.net/" …
   xmlns:tns="http://server.soap.ilkj.net/"



(2.)<wsdl:types …

    这个元素会通过<xs:element … 声明几个复杂数据类型的元素。
一般首先你看到的是Web 服务中的方法参数、返回值所涉及的所有复杂(complex)类型的
元素定义<xs:element …,其中name 属性值是这个复杂类型的JAXB 注解的name 属性值,
type 属性是tns:+JAXB 注解的name 属性值的全小写形式(上例中的方法参数、返回值只涉
及一个复杂类型Customer,Customer 的@XmlRootElement 注解的name 属性值为Customer,
因此你会看到<xs:element name="Customer" type="tns:customer" />)。
再向下你会看到XXX 元素和XXXResponse 元素,其中XXX 是方法名称(你可以使用
@WebMethod 的operationName 属性值指定XXX 的值),XXX 是对方法参数的封装,
XXXResponse 是对返回值的封装

最后你会看到一组
<xs:complexType … 元素, 这个元素通过name 属性关联到<xs:element … ,它为前面定义的元素指定封装的具体内容(通过子元素<xs:sequence … 指定)


如下:
<xs:element name="getUserList" type="tns:getUserList" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="getUserListResponse" type="tns:getUserListResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="getUsers" type="tns:getUsers" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="getUsersResponse" type="tns:getUsersResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="sayHi" type="tns:sayHi" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="sayHiResponse" type="tns:sayHiResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="sayHiToUser" type="tns:sayHiToUser" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  <xs:element name="sayHiToUserResponse" type="tns:sayHiToUserResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
- <xs:complexType name="getUsers" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  </xs:complexType>
- <xs:complexType name="getUsersResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element minOccurs="0" name="return" type="tns:IntegerUserMap" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
  </xs:sequence>
  </xs:complexType>



(3.)<wsdl:message …

    这个元素将输入参数(方法参数)和响应结果(方法返回值)、受检查的异常信息包装为消
息。

(4.)<wsdl:portType …

    这个元素指定Web 服务的端口类型(Web 服务会被发布为EndPoint 端点服务),它的name
属性默认为接口名称(你可以使用@WebService 注解的name 属性指定值)。这个元素包含
了一系列的<wsdl:operation …子元素指定该端点服务包含了那些操作( 方法) ,
<wsdl:operation …的子元素<wsdl:input …、<wsdl:output …指定操作的输入输出(通过属性
message 绑定到前面声明过的消息)。

(5.)<wsdl:binding …

    这个元素将前面最终的端点服务绑定到SOAP 协议(你可以看出来WSDL 从上到下依次有
着依赖关系),其中的<soap:xxx … 的style、use 分别可以使用SOAPBinding 注解的style、
use 属性指定值、<wsdl:operation … 指定公开的操作(方法)。这部分XML 指定最终发布
的Web 服务的SOAP 消息封装格式、发布地址等。


- <wsdl:binding name="firstWsSoapBinding" type="tns:FirstWs" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
- <wsdl:operation name="getUsers" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:operation soapAction="" style="document" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
- <wsdl:input name="getUsers" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
  </wsdl:input>
- <wsdl:output name="getUsersResponse" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="sayHiToUser" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:operation soapAction="" style="document" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
- <wsdl:input name="sayHiToUser" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
  </wsdl:input>
- <wsdl:output name="sayHiToUserResponse" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
  </wsdl:output>
  </wsdl:operation>

(6.)<wsdl:service …
    这个元素的name 属性指定服务名称(这里与根元素的name 属性相同),子元素<wsdl:port…
的name 属性指定port 名称,子元素<soap:address … 的location 属性指定Web 服务的地址。

- <wsdl:service name="firstWs" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:port binding="tns:firstWsSoapBinding" name="FirstWsImplPort" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <soap:address location="http://localhost:8080/ws_cxf_firstwswithspring/yeeku-services/crazyit"         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" />
  </wsdl:port>
  </wsdl:service>



原创粉丝点击