WSDL概念
WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问。
WSDL 文档结构
首先发布一个简单的WebService(参照:【WebService】使用JDK开发WebService(二)),在发布的WebService地址后面加上'?wsdl',得到wsdl文件地址(http://127.0.0.1:8989/test-webservice/hellows?wsdl),使用浏览器打开。
重要标签说明:
types - 数据类型(标签)定义的容器,里面使用schema定义了一些标签结构供message引用
message - 通信消息的数据结构的抽象类型化定义。引用types中定义的标签
operation - 对服务中所支持的操作的抽象描述,一个operation描述了一个访问入口的请求消息与响应消息对。
portType - 对于某个访问入口点类型所支持的操作的抽象集合,这些操作可以由一个或多个服务访问点来支持。
binding - 特定端口类型的具体协议和数据格式规范的绑定。
service- 相关服务访问点的集合
port - 定义为协议/数据格式绑定与具体Web访问地址组合的单个服务访问点。
1、文档结构
1 <definitions> 2 <types> 3 <schema> 4 <element> 5 </types> 6 7 <message> 8 <part> 9 </message> 10 11 <portType> 12 <operation> 13 <input> 14 <output> 15 </portType> 16 17 <binding> 18 <operation> 19 <input> 20 <output> 21 </binding> 22 23 <service> 24 <port> 25 <address> 26 </service> 27 </definitions>
2、文档详解
http://127.0.0.1:8989/test-webservice/hellows?wsdl文件详解
1 <?xml version="1.0" encoding="UTF-8"?> 2 <definitions 3 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 4 xmlns:wsp="http://www.w3.org/ns/ws-policy" 5 xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" 6 xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" 7 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 8 xmlns:tns="http://ws.test.com/" 9 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 10 xmlns="http://schemas.xmlsoap.org/wsdl/" 11 targetNamespace="http://ws.test.com/" 12 name="HelloWSImplService"> 13 <!-- 14 types 15 schema : 定义了一些标签结构 16 --> 17 <types> 18 <xsd:schema> 19 <!-- 此处引用的sehemaLocation地址,可以使用浏览器打开,获取schema约束 --> 20 <xsd:import namespace="http://ws.test.com/" 21 schemaLocation="http://127.0.0.1:8989/test-webservice/hellows?xsd=1"></xsd:import> 22 </xsd:schema> 23 </types> 24 25 <!-- 26 message : 用于定义消息的结构 soap消息 27 part :指定引用types中定义的标签片段 28 --> 29 <message name="sayHello"> 30 <part name="parameters" element="tns:sayHello"></part> 31 </message> 32 <message name="sayHelloResponse"> 33 <part name="parameters" element="tns:sayHelloResponse"></part> 34 </message> 35 36 <!-- 37 portType : 用来定义服务器端的SEI 38 operation : 用来指定SEI中处理请求的方法 39 input : 指定客户端应用传过来的数据,会引用上面的定义的<message> 40 output : 指定服务器端返回给客户端的数据,会引用上面定义的<message> 41 --> 42 <portType name="HelloWSImpl"> 43 <operation name="sayHello"> 44 <input wsam:Action="http://ws.test.com/HelloWSImpl/sayHelloRequest" message="tns:sayHello"></input> 45 <output wsam:Action="http://ws.test.com/HelloWSImpl/sayHelloResponse" message="tns:sayHelloResponse"></output> 46 </operation> 47 </portType> 48 49 <!-- 50 binding : 用于定义SEI的实现类 51 type属性:引用上面的<portType> 52 <soap:binding style="document"> :绑定的数据是一个document(xml) 53 operation : 用来定义实现的方法 54 <soap:operation style="document" /> 传输的是document(xml) 55 input : 指定客户端引用传过来的数据 56 <soap:body use="literal"> :文本数据 57 output : 指定服务端返回给客户端的数据 58 <soap:body use="literal"> :文本数据 59 --> 60 <binding name="HelloWSImplPortBinding" type="tns:HelloWSImpl"> 61 <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding> 62 <operation name="sayHello"> 63 <soap:operation soapAction=""></soap:operation> 64 <input> 65 <soap:body use="literal"></soap:body> 66 </input> 67 <output> 68 <soap:body use="literal"></soap:body> 69 </output> 70 </operation> 71 </binding> 72 73 <!-- 74 service : 一个webservice的容器 75 name属性 : 它用已指定客户端容器类 76 port : 用来指定一个服务器端处理请求的入口(就是SEI的实现) 77 binding属性 : 引用上面定义的<binding> 78 address : 当前webservice的请求地址 79 --> 80 <service name="HelloWSImplService"> 81 <port name="HelloWSImplPort" binding="tns:HelloWSImplPortBinding"> 82 <soap:address location="http://127.0.0.1:8989/test-webservice/hellows"></soap:address> 83 </port> 84 </service> 85 </definitions>
引用的http://127.0.0.1:8989/test-webservice/hellows?xsd=1, schema约束如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --> 3 <!-- 4 shecma约束 5 6 用于请求: 7 <sayHello> 8 <arg0>string</arg0> 9 </sayHello> 10 11 用于响应: 12 <sayHelloResponse> 13 <return>string</return> 14 </sayHelloResponse> 15 16 --> 17 <xs:schema xmlns:tns="http://ws.test.com/" 18 xmlns:xs="http://www.w3.org/2001/XMLSchema" 19 version="1.0" 20 targetNamespace="http://ws.test.com/"> 21 22 <xs:element name="sayHello" type="tns:sayHello"/> 23 24 <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/> 25 26 <xs:complexType name="sayHello"> 27 <xs:sequence> 28 <xs:element name="arg0" type="xs:string" minOccurs="0"/> 29 </xs:sequence> 30 </xs:complexType> 31 32 <xs:complexType name="sayHelloResponse"> 33 <xs:sequence> 34 <xs:element name="return" type="xs:string" minOccurs="0"/> 35 </xs:sequence> 36 </xs:complexType> 37 </xs:schema>
3、文档图解图
注:可以通过查看webservice的请求消息和响应消息(【WebService】使用JDK开发WebService(二)--》使用JDK开发WebService--》a、开发WebService服务端--》7、查看发送消息和响应消息的具体内容),来与wsdl文件中的message进行相互验证