1、逐个分析wsdl文件中的元素:

<types>:数据类型定义的容器,一般使用 xml schema类型系统。

<message>:通信消息的数据结构的抽象化定义,使用<types>定义的数据类型来定义整个消息的数据结构。(portType相当于一个类或者接口)

<operation>:对服务中所支持的操作的抽象描述,一般单个<operation>描述了一个访问入口的请求/响应消息对。

<portType>:服务访问点所支持的操作的抽象集合,相当于一个类。

<binding>:特定端口类型(portType)具体协议和数据格式规范的绑定(绑定这里是个名词)。

<port>:  具体的绑定(binding)与web地址组合的单个访问点。

<service>:相关服务访问点(port)的集合。

2、关系图(此图非原创)                  

3、例子讲解

 <?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
targetNamespace="http://com.liuxiang.xfireDemo/HelloService"
xmlns:tns="http://com.liuxiang.xfireDemo/HelloService"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://com.liuxiang.xfireDemo/HelloService">
<xsd:element name="sayHellorequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1"
name="name" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="sayHelloResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1"
name="out" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="sayHelloResponse">
<wsdl:part name="parameters" element="tns:sayHelloResponse" />
</wsdl:message>
<wsdl:message name="sayHelloRequest">
<wsdl:part name="parameters" element="tns:sayHelloRequest" />
</wsdl:message>
<wsdl:portType name="HelloServicePortType">
<wsdl:operation name="sayHellorequest">
<wsdl:input name="sayHelloRequest"
message="tns:sayHelloRequest" />
<wsdl:output name="sayHelloResponse"
message="tns:sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloServiceHttpBinding"
type="tns:HelloServicePortType">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="sayHello">
<wsdlsoap:operation soapAction="" />
<wsdl:input name="sayHelloRequest">
<wsdlsoap:body use="literal" />
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<wsdlsoap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloService">
<wsdl:port name="HelloServiceHttpPort"
binding="tns:HelloServiceHttpBinding">
<wsdlsoap:address
location="http://localhost:8080/xfire/services/HelloService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

4、逐部分介绍

<definition>

 <wsdl:definitions
targetNamespace="http://com.liuxiang.xfireDemo/HelloService"
xmlns:tns="http://com.liuxiang.xfireDemo/HelloService"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
</wsdl:definitions>

主要是提供一个命名空间、整个wsdl文档中用到的xml规范。一般可以通用。

xmlns:xsd="http://www.w3.org/2001/XMLSchema"   
xmlns:变量名="协议源",定义的这个变量名,可以在后面定义具体参数类型时用到。

<type>

<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://com.liuxiang.xfireDemo/HelloService">
<xsd:element name="sayHelloRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1"
name="name" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="sayHelloResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1"
name="out" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>

这部分可以单独定义为一个文件,因为有时候需要定义的元素会比较多,单独写一个文件,用import引入到需要用的wsdl文件。

这里定义了两个元素: sayHelloRequest/sayHelloResponse,就相当于在写一个普通类时定义变量或者对象引用,此处类似于对象引用。

此处这两个元素都是复杂类型,sequence定义该复杂类型里面的属性变量。

<message>

<wsdl:message name="sayHelloResponse">
<wsdl:part name="parameters" element="tns:sayHelloResponse" />
</wsdl:message>
<wsdl:message name="sayHelloRequest">
<wsdl:part name="parameters" element="tns:sayHelloRequest" />
</wsdl:message>

消息格式的抽象定义。

<portType>

     <wsdl:portType name="HelloServicePortType">
<wsdl:operation name="sayHelloRequest">
<wsdl:input name="sayHelloRequest"
message="tns:sayHelloRequest" />
<wsdl:output name="sayHelloResponse"
message="tns:sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>

<portType>定义了抽象接口,<operation>定义了接口里面的方法,input表示输入参数、output表示输出参数。

这里刚开始理解起来比较绕,使用wsdl的有两类人:客户端、服务端。

写好wsdl后,需要使用工具自动生成Java代码(一般通过cxf命令生成),客户端和服务端的代码稍有区别:

服务端: public sayHelloResponse sayHelloRequest(sayHelloRequest parameters)//

客户端: public sayHelloResquest sayHelloRequest(sayHelloResponse parameters)//

<binding>

binding元素将一个抽象portType映射到一组具体协议(SOAO和HTTP)、消息传递样式、编码样式。通常binding元素与协议专有的元素和在一起使用,本文中的例子:

    <wsdl:binding name="HelloServiceHttpBinding"
type="tns:HelloServicePortType">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="sayHello">
<wsdlsoap:operation soapAction="" />
<wsdl:input name="sayHelloRequest">
<wsdlsoap:body use="literal" />
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<wsdlsoap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

service元素和port元素

service元素包含一个或者多个port元素,其中每个port元素表示一个不同的Web服务。

port元素将URL赋给一个特定的binding,甚至可以使两个或者多个port元素将不同的URL赋值给相同的binding。

文档中的例子:

    <wsdl:service name="HelloService">
<wsdl:port name="HelloServiceHttpPort"
binding="tns:HelloServiceHttpBinding">
<wsdlsoap:address
location="http://localhost:8080/xfire/services/HelloService" />
</wsdl:port>
</wsdl:service>

这部分是具体的Web服务的定义,在这个名为HelloService的Web服务中,提供了一个服务访问入口,

访问地址是http://localhost:8080/xfire/services/HelloService,使用的消息模式是由前面的binding所定义的。

以后慢慢完善之。。。

wsdl透明解析的更多相关文章

  1. 学习 WebService 第二步:知识准备——WSDL文件解析

    原文地址:https://www.cnblogs.com/yzw23333/p/7245104.html Web service中一个 WSDL 对应一个 web service地址. 可以想象成一个 ...

  2. WSDL实例解析

    WSDL的主要文档元素 WSDL文档可以分为两部分.顶部分由抽象定义组成,而底部分则由具体描述组成.抽象部分以独立于平台和语言的方式定义SOAP消息,它们并不包含任何随 机器或语言而变的元素.这就定义 ...

  3. webservice 之 WSDL的解析

    先看一个wsdl, <?xml version="1.0" encoding="UTF-8" standalone="no"?> ...

  4. wsdl 结构解析

    webservice的跨平台特性要求它必须有某种手段来对服务进行自我描述,使不同的语言能正确理解如何调用该服务.webservice通过WSDL(Web Services Description La ...

  5. 创建WSDL项目

    WSDL文件是测试基于soap的服务,他们定义实际暴露服务和要求SoapUI生成测试,要求信息,验证和MockServices. SoapUI支持最广泛使用的1.1版本的WSDL和SOAP 1.1和1 ...

  6. WSDL中文版——详解

    为什么使用WSDL? 像Internet协议之类的标准有没有为权威所利用,或者人们这样看待它是因为顺之所获的好处远远超出了代价?曾经有许多试图建立的标准都流产了.有时候,那些还没有普遍使用的标准甚至由 ...

  7. webservice------UDDI SOAP WSDL 之间的关系

    [  真的是服了一些博客.....啰里啰唆的将一堆==   根本不知道讲的是什么 ... 在描述一个定义之前  (不如先通俗的讲它是干什么的)] SOAP(Simple Object Access P ...

  8. java环境下wsimport编译Wsdl

    使用命令提示符进行操作:首先CD至java jdk/bin目录下.先bin目录下执行以下命令即可: -----------------------------服务需求放置的位置------------ ...

  9. SOAP、WSDL、 UDDI之间的关系

    SOAP(Simple Object Access Protocol) 简单对象访问协议: WSDL(Web Services Description Language) Web服务描述语言: UDD ...

随机推荐

  1. asp.net MVC Razor 语法(2)

    变量是用于存储数据的命名实体. 变量 变量用于存储数据. 变量名必须以字母字符开头,不能包含空格和保留字符. 变量可以是某个具体的类型,指示其所存储的数据类型.字符串变量存储字符串值 ("W ...

  2. xcode UIImageView创建、图片加载、 音频文件播放、 延迟调用

    代码创建 /** 创建UIImageView */ UIImageView * imageView=[[UIImageView alloc]init]; /** 设置尺寸位置 */ imageView ...

  3. T-SQL语句中中括号([])的用法是什么,什么时候该用

    加了[]是为了防止歧义,使计算机能识别.有些字段可能是关键字,这时候你直接用字段名就会报错,如果加了[]就可以正常执行了

  4. Gridpanel多种操作帮助文档

    1.Ext.grid.GridPanel 主要配置项: store:表格的数据集 columns:表格列模式的配置数组,可自动创建ColumnModel列模式 autoExpandColumn:自动充 ...

  5. javascript封装自定义滚动条方法,可自定义四个边框滚动条

    还是根据我的个人习惯封装了一个方法 setScroll({ box :父盒子DOM对象, content : 内容盒子DOM对象, scrollall : 滚动条大盒子DOM对象, scroll : ...

  6. Mongodb安装和基本命令

    本人是在Centos中安装的mongodb 1.下载mongodb curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2. ...

  7. java附件上传下载大字段版

    public int up2(Map map) { StringBuffer insertSQL = new StringBuffer(); insertSQL.append("insert ...

  8. Mysql mysqlimport 导入数据

    在mysql 数据库中可以用 mysqlimport 工具来实现数据的导入!mysqlimport 导入数据简单,但是这个也要满足一定的条件 1.既然是把数据导入到数据库,你总有一个数据库用户账号吧 ...

  9. Linux同平台Oracle数据库整体物理迁移

    Linux同平台数据库整体物理迁移需求:A机器不再使用,要将A机器的Oracle迁移到B机器.之前写过类似需求的文章: http://www.linuxidc.com/Linux/2015-05/11 ...

  10. ElaticSearch网站

    http://www.tuicool.com/articles/r2QJVr http://so.searchtech.pro/articles/2013/06/16/1371392427213.ht ...