CXF学习-WSDL文档深入了解

来源:互联网 发布:在线支付php源码 编辑:程序博客网 时间:2024/06/06 15:36
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"><!--</span>
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.ws.cxf/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://impl.ws.cxf/" name="HelloWorldWS"><import namespace="http://ws.cxf/" location="http://10.0.6.17/fightUp?wsdl=1"/><binding xmlns:ns1="http://ws.cxf/" name="HelloWorldWSPortBinding" type="ns1:HelloWorld"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="sayHi"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation><operation name="getCatByUser"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="HelloWorldWS"><port name="HelloWorldWSPort" binding="tns:HelloWorldWSPortBinding"><soap:address location="http://10.0.6.17/fightUp"/></port></service></definitions>

-----------------------------------接口实现类-----------------------------------


targetNameSpace相当于java里面的package

xmlns相当于Java里面的import :


types元素 schema文件

<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><xs:schema xmlns:tns="http://ws.cxf/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://ws.cxf/"><xs:element name="getCatByUser" type="tns:getCatByUser"/><xs:element name="getCatByUserResponse" type="tns:getCatByUserResponse"/><xs:element name="sayHi" type="tns:sayHi"/><xs:element name="sayHiResponse" type="tns:sayHiResponse"/><xs:complexType name="sayHi"><xs:sequence><xs:element name="arg0" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="sayHiResponse"><xs:sequence><xs:element name="return" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="getCatByUser"><xs:sequence><xs:element name="arg0" type="tns:user" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="user"><xs:sequence><xs:element name="address" type="xs:string" minOccurs="0"/><xs:element name="id" type="xs:int" minOccurs="0"/><xs:element name="name" type="xs:string" minOccurs="0"/><xs:element name="pass" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="getCatByUserResponse"><xs:sequence><xs:element name="return" type="tns:cat" minOccurs="0" maxOccurs="unbounded"/></xs:sequence></xs:complexType><xs:complexType name="cat"><xs:sequence><xs:element name="color" type="xs:string" minOccurs="0"/><xs:element name="id" type="xs:int" minOccurs="0"/><xs:element name="name" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:schema>
接口文件
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><definitions xmlns:tns="http://ws.cxf/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.cxf/"><types><xsd:schema><xsd:import namespace="http://ws.cxf/" schemaLocation="http://10.0.6.17/fightUp?xsd=1"/></xsd:schema></types><message name="sayHi"><part name="parameters" element="tns:sayHi"/></message><message name="sayHiResponse"><part name="parameters" element="tns:sayHiResponse"/></message><message name="getCatByUser"><part name="parameters" element="tns:getCatByUser"/></message><message name="getCatByUserResponse"><part name="parameters" element="tns:getCatByUserResponse"/></message><portType name="HelloWorld"><operation name="sayHi"><input message="tns:sayHi"/><output message="tns:sayHiResponse"/></operation><operation name="getCatByUser"><input message="tns:getCatByUser"/><output message="tns:getCatByUserResponse"/></operation></portType></definitions>

一次webService调用,不是方法的调用,而是发送soap消息

1、客户端把调用参数,转化为xml文档,xml文档必须符合wsdl定义的格式。(SOAP消息,input消息)

2、通过网络,把xml文档片段传给服务器。

3、服务器收到xml文档片段。

4、服务器解析xml文档片段,提取其中的数据,并把数据转化为调用web Service所需要的参数值。

5、服务器执行方法。

6、把执行方法得到的返回值,再次转化生成xml文档片段(soap消息)xml文档必须符合wsdl定义的格式。(SOAP消息,output消息)

7、通过网络,把xml文档片段传给客户端。

8、客户端接收xml文档片段。

9、客户端解析xml文档片段,提取其中的数据,并把数据转化为调用web Service的返回值。


从上面web Service调用本质来看,该语言支持xml;以xml作为载体,进行数据传递。

以上文件均有上篇博文CXF学习-2得来。


------------------------------------------------wsdl文档的结构------------------------------------------------------

wsdl文档描述了web Service 的三个方面:

1、what :包含了哪些操作;

2、how:该web service 怎样调用;

3、where: 在哪里可以访问地址。


只要得到web Service WSDL文档,就可以调用web service了。

0 0