wsdl文档概述

来源:互联网 发布:linux ps命令中括号 编辑:程序博客网 时间:2024/05/23 01:15

web service 三个基础技术

  1. wsdl
  2. soap:simple object access protocol简单对象访问协议
  3. uddi

wsdl文档–web service definition language

用浏览器访问:http://IP地址:端口号/自定义服务名?wsdl得到如下文档,这里代表的是这个服务的实现类:

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://helloworldimpl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://helloworldimpl/" name="MyFirstService"><import namespace="http://helloworld/" location="http://10.1.14.67:10000/MyFristService?wsdl=1"/><binding xmlns:ns1="http://helloworld/" 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></binding><service name="MyFirstService"><port name="HelloWorldWsPort" binding="tns:HelloWorldWsPortBinding"><soap:address location="http://10.1.14.67:10000/MyFristService"/></port></service></definitions>
  • targetNamespace相当于java的包,在这里,里面的内容根据实现类java文件的包来的。
  • xmlns 相当于java中的import。经常看到xmlns后面还会跟着有冒号的短语,例如:xmlns:xsi=“http://xxxxxxxx”,下面解释一下这个冒号的作用:就像在java中,sql包下有个date类,util包下也有一个date类,如果我们在一个java文件中,使用了date类,并且同时引入这两个包,那么编译器会报错,说:不明确此类到底是哪个包下面的。xml提供了一个机制,对于引入的xsd文件中存在相同标签的情况,使用在xmlns:自定义短语的形式来区别,这样,在使用相同的标签的情况下,就可以进行判别了,而不用担心包的问题,使用时,自定义短语:使用值 即可。例如 想使用的属性schemalocation重复,就这样 xsi:schemalocation=‘xxx’(这里的xsi是举例,不是固定的),就可以说明是xmlns:xsi这个文件里面的schemalocation标签了。

  • import标签与java的import意义相同,引入的通常是实现类的接口。里面的location属性可以直接在浏览器中访问,访问到的就是代表接口的文档了。

  • binding 里面是实现类endpointinterface写入的接口。
  • service里面写的是实现类servicename的内容。

文档分为两部分(刚才上面提到的,实现类,和接口)

web service 接口部分:

types标签,一个标准schema文档,message代表函数。因为服务端与客户端是web通信,所以有请求和返回,那么就是一个函数对应两个message,从属性名中也可以看出来对应关系。message里面的part标签代表元素,元素的定义在schema里面,可以在import里面的schemalocation里面找到,进行浏览器访问即可。porttype代表这个接口,里面的operation代表一个操作(其实就是方法,不过webservice里面更多说方法)。operation里面的input和output两个标签,input代表输入消息,output代表返回消息,这里的消息对应message里面的消息。message再去schema里面查找,查找element标签,element的type属性对应其中的带有type字样的标签,这里面定义了函数的参数。

这里强调一点,一次webservice调用,其实不是方法调用,而是发送一个soap消息(即xml片段)

web service实现部分:

import:引入标签binding:详细定义了每个web service操作service:定义了web service服务名称,以及绑定的地址。

调用一次web service的本质

  1. 客户端把调用方法的参数,转换成xml文档片段(也叫soap消息),该文档片段必须符合wsdl定义的格式。
  2. 通过网络,把xml文档片段传给服务器。
  3. 服务器接收到xml文档片段
  4. 服务器解析xml文档片段。提取其中的数据,并转换成调用web service所需要的参数值。
  5. 服务器执行相应方法。
  6. 把服务器端的执行结果转换为xml文档片段
  7. 通过网络,将文档片段发送给客户端
  8. 客户端接收
  9. 客户端解析

通俗的说 wsdl文档描述了web service以下三个方面

  • 该web service包含了那些‘操作’.
  • 操作怎样调用
  • 服务地址
0 0