wsdl透明解析
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透明解析的更多相关文章
- 学习 WebService 第二步:知识准备——WSDL文件解析
原文地址:https://www.cnblogs.com/yzw23333/p/7245104.html Web service中一个 WSDL 对应一个 web service地址. 可以想象成一个 ...
- WSDL实例解析
WSDL的主要文档元素 WSDL文档可以分为两部分.顶部分由抽象定义组成,而底部分则由具体描述组成.抽象部分以独立于平台和语言的方式定义SOAP消息,它们并不包含任何随 机器或语言而变的元素.这就定义 ...
- webservice 之 WSDL的解析
先看一个wsdl, <?xml version="1.0" encoding="UTF-8" standalone="no"?> ...
- wsdl 结构解析
webservice的跨平台特性要求它必须有某种手段来对服务进行自我描述,使不同的语言能正确理解如何调用该服务.webservice通过WSDL(Web Services Description La ...
- 创建WSDL项目
WSDL文件是测试基于soap的服务,他们定义实际暴露服务和要求SoapUI生成测试,要求信息,验证和MockServices. SoapUI支持最广泛使用的1.1版本的WSDL和SOAP 1.1和1 ...
- WSDL中文版——详解
为什么使用WSDL? 像Internet协议之类的标准有没有为权威所利用,或者人们这样看待它是因为顺之所获的好处远远超出了代价?曾经有许多试图建立的标准都流产了.有时候,那些还没有普遍使用的标准甚至由 ...
- webservice------UDDI SOAP WSDL 之间的关系
[ 真的是服了一些博客.....啰里啰唆的将一堆== 根本不知道讲的是什么 ... 在描述一个定义之前 (不如先通俗的讲它是干什么的)] SOAP(Simple Object Access P ...
- java环境下wsimport编译Wsdl
使用命令提示符进行操作:首先CD至java jdk/bin目录下.先bin目录下执行以下命令即可: -----------------------------服务需求放置的位置------------ ...
- SOAP、WSDL、 UDDI之间的关系
SOAP(Simple Object Access Protocol) 简单对象访问协议: WSDL(Web Services Description Language) Web服务描述语言: UDD ...
随机推荐
- 关于cocos2d安装时编译不成功(个人心得)
在解压cocos2d执行vs2010.sln时错误发生不能成功生成.遇到这样的错误: 1>c:\program files\microsoft sdks\windows\v7.0a\includ ...
- linux性能监控三张图
一.监控 二.测试 三.优化
- asp.net软件测试学习
ormaping类是,将数据操作封装起来的一种数据操作方法,在测试的时候,如果说,insert之后对obj对象赋值赋值,每个属性应该对应自己的objDataRow["REGISTERID&q ...
- 全球最快的JS模板引擎
废话不多说,先上测试: 亲测请访问:[在线测试地址]单次结果不一定准确,请多测几次. tppl 的编译渲染速度是著名的 jQuery 作者 John Resig 开发的 tmpl 的 43 倍!与第二 ...
- C++链接库
静态链接库在程序编译链接过程中就导入lib文件并且包含在生成的exe文件里,而动态链接库DLL是在程序运行中由程序加载和卸载的,也就是说它是动态的,当然动态链接库DLL也可以静态加载当做静态来用: 静 ...
- 多关键字排序(里面有关于操作符(<<运算符 和 >>运算符 )的重载)
一种排序 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都是整数:现 ...
- BZOJ 1406: [AHOI2007]密码箱( 数论 )
(x+1)(x-1) mod N = 0, 枚举N的>N^0.5的约数当作x+1或者x-1... ------------------------------------------------ ...
- 安装爬虫scrapy
使用easy_install安装scrapy,报错 error: Setup script exited with error: command 'gcc' failed with exit stat ...
- python xlrd对excel的读取功能
工作簿 xlrd.open_workbook('test.xls') workbook.dump() workbook.nsheets workbook.sheets() workbook.sheet ...
- 查看、修改oracle字符集,查看oracle版本
1.查看数据库字符集 数据库服务器字符集select * from nls_database_parameters,其来源于props$,是表示数据库的字符集. 客户端字符集环境select * fr ...