首页 > 学院 > 开发设计 > 正文

webservice学习笔记(5)--WSDL文档

2019-11-08 01:08:01
字体:
来源:转载
供稿:网友

1.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://ws.day01_ws.atguigu.com/"	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 	xmlns:ns1="http://schemas.xmlsoap.org/soap/http"	name="HelloWSImplService" 	targetNamespace="http://ws.day01_ws.atguigu.com/">	<!-- 		types 			schema : 定义了一些标签结构	 -->	<wsdl:types>		<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"			xmlns:tns="http://ws.day01_ws.atguigu.com/" elementFormDefault="unqualified"			targetNamespace="http://ws.day01_ws.atguigu.com/" version="1.0">						<!-- 				//用于请求				<sayHello>					<arg0>string</arg0>				</sayHello>					<q0:sayHello>						<arg0>BB</arg0> 					</q0:sayHello>									//用于响应				<sayHelloResponse>					<return>string</return>				</sayHelloResponse>					<ns2:sayHelloResponse">						<return>Hello BB</return> 					</ns2:sayHelloResponse>			 -->						<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: 用来定义消息的结构   soap消息			part : 指定引用types中定义的标签片断	 -->		<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: 用来定义服务器端的SEI			Operation : 用来指定SEI中的处理请求的方法				input : 指定客户端应用传过来的数据, 会引用上面的定义的<message>				output : 指定服务器端返回给客户端的数据, 会引用上面的定义的<message>	 -->	<wsdl:portType name="HelloWS">		<wsdl:operation name="sayHello">			<wsdl:input message="tns:sayHello" name="sayHello">			</wsdl:input>			<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse">			</wsdl:output>		</wsdl:operation>	</wsdl:portType>		<!-- 		binding : 用于定义SEI的实现类			type属性: 引用上面的<portType>			<soap:binding style="document"> : 绑定的数据是一个document(xml)			operation : 用来定义实现的方法				<soap:operation style="document" /> 传输的是document(xml)				input: 指定客户端应用传过来的数据					<soap:body use="literal" /> : 文本数据				output : 指定服务器端返回给客户端的数据					<soap:body use="literal" /> : 文本数据	 -->		<wsdl:binding name="HelloWSImplServiceSoapBinding" type="tns:HelloWS">		<soap:binding style="document"			transport="http://schemas.xmlsoap.org/soap/http" />		<wsdl:operation name="sayHello">			<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>		<!-- 		service : 一个webservice的容器			name属性: 它用一指定客户端容器类			port : 用来指定一个服务器端处理请求的入口(就SEI的实现)				binding属性: 引用上面定义的<binding>				address : 当前webservice的请求地址	 -->	<wsdl:service name="HelloWSImplService">		<wsdl:port binding="tns:HelloWSImplServiceSoapBinding" name="HelloWSImplPort">			<soap:address location="http://192.168.10.165:8888/day01_ws/hellows" />		</wsdl:port>	</wsdl:service></wsdl:definitions>

2.WSDL文档结构

<definitions>

  <types>

  <schema>定义约束条件

  <element>

   </types>

    <message>消息(请求消息和响应消息)

         <part>

    </message>

    <portType>

    <operation>

       <input>

       <output>

       </portType>

        <binding> 

     <operation>

         <input>

        <output>

     </binding>

    <service> 

       <port>

      <address>

   </service>

</definitions>

3.消息格式

4元素

WSDL 元素基于XML语法描述了与服务进行交互的基本元素:

(1)Type(消息类型):数据类型定义的容器,它使用某种类型系统(如 XSD)。

(2)Message(消息):通信数据的抽象类型化定义,它由一个或者多个 part组成。用来定义消息的结构

(3)Part:消息参数,用来指定tyes中定义的片段

(4)Operation(操作):对服务所支持的操作进行抽象描述

WSDL定义了四种操作:

       1.单向(one-way):端点接受信息;

2.请求-响应(request-response):端点接受消息,然后发送相关消息;

3.要求-响应(solicit-response):端点发送消息,然后接受相关消息;

4.通知(notification[2]):端点发送消息。

(5)Port Type(端口类型):特定端口类型的具体协议和数据格式规范。

(6)Binding:特定端口类型的具体协议和数据格式规范。

(7)Port:定义为绑定和网络地址组合的单个端点。

(8)Service:相关端口的集合,包括其关联的接口、操作、消息等。

5元素之间的关系


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表