WebService基于Web的服务
理解什么是服务:
l 现在的应用程序变得越来越复杂,甚至只靠单一的应用程序无法完成全部的工作。更别说只使用一种语言了。
l 大家在写应用程序查询数据库时,并没有考虑过为什么可以将查询结果返回给上层的应用程序,甚至认为,这就是数据库应该做的,其实不然,这是数据库通过TCP/IP协议与另一个应用程序进行交流的结果,而上层是什么样的应用程序,是用什么语言,数据库本身并不知道,它只知道接收到了一份协议,这就是sql92查询标准协议。
l 目前的云计算、云查杀都是一种服务,现在比较流行的说法是SOA(面向服务的框架)。
l 既然数据库可以依据某些标准对外部其他应用程序提供服务、而且不关心对方使用什么语言,那我们为什么就不能实现跨平台、跨语言的服务呢?
l 只要我们用Java写的代码,可以被任意的语言所调用,我们就实现了跨平台,跨语言的服务!
什么是WebService
简说:如果说Java是跨平台的语言,那么WebService就是跨语言的技术。
WebService可以让多个进程之间实现数据交换,即进程间通讯。
无论某个进程运行要互联网的任何地点,无论进程是有什么语言写成的,都可以互相访问并传输数据。最后,WebService是基于HTTP和XML的技术。WebService的商业应用:
网上支付-支付宝。
银联-提供统一的WebService,实现银行之间的转账付款。
在种不同的终端设备上如手机、iPad实时查询天气预报、股票行情。
- WebService,顾名思义就是基于Web的服务。它使用Web(HTTP)方式,接收和响应外部系统的某种请求。从而实现远程调用.
- 我们可以调用互联网上查询天气信息Web服务,然后将它嵌入到我们的程序(C/S或B/S程序)当中来,当用户从我们的网点看到天气信息时,他会认为我们为他提供了很多的信息服务,但其实我们什么也没有做,只是简单了调用了一下服务器上的一段代码而已。
- 学习WebSerice可以将你的服务(一段代码)发布到互联网上让别人去调用,也可以调用别人机器上发布的WebService,就像使用自己的代码一样.。
简单的网络应用:
现在我们来看jdk中对于webservice的支持,并且有其工具函数的存在。
去是使用:
一:讲解的是手动怎么从外网上的wsdl上,用jdk中的工具来获取webservice代码呢?
D:\a>wsimport-s . http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx
?wsdl
参数帮助:
C:\Users\YUHUADONG\Desktop>wsimport
Missing WSDL_URI
Usage: wsimport [options]<WSDL_URI>
where [options] include:
-b <path> specify jaxws/jaxb binding files or additional schem
as
(Each <path>must have its own -b)
-B<jaxbOption> Pass this option to JAXB schema compiler
-catalog <file> specify catalog file to resolve external entity refe
rences
supports TR9401,XCatalog,and oasis XML Catalog for
mat.
-d <directory> specify where to place generated output files
-extension allowvendor extensions - functionality not specifie
d
by the specification. Use of extensions may
result inapplications that are not portable or
may notinteroperate with other implementations
-help displayhelp
-httpproxy:<host>:<port> specify a HTTP proxy server (port defaults to 8080)
-keep keepgenerated files
-p <pkg> specifies the target package
-quiet suppresswsimport output
-s <directory> specify where to place generated source files
-target <version> generate code as per the given JAXWS spec version
e.g. 2.0 willgenerate compliant code for JAXWS 2.0
spec
-verbose outputmessages about what the compiler is doing
-version printversion @R_664_4045@ion
-wsdllocation <location> @WebServiceClient.wsdlLocation value
Extensions:
-XadditionalHeaders mapheaders not bound to request or response messa
ge to
Java methodparameters
-Xauthfile fileto carry authorization @R_664_4045@ion in the for
mat
http://username:[email protected]/stock?wsdl
-Xdebug printdebug @R_664_4045@ion
-Xno-addressing-databinding enable binding of W3C EndpointReferenceTypeto Jav
a
-Xnocompile do notcompile generated Java files
Examples:
wsimport stock.wsdl -b stock.xml -b stock.xjb
wsimport -d generated http://example.org/stock?wsdl
C:\Users\YUHUADONG\Desktop>
-----------------------------------------------------------------------------------------------------------------------------------------------
saop协议:
soap=xml+post+http,tld
名词1:XML. Extensible MarkuP Language -扩展性标记语言
XML,用于传输格式化的数据,是Web服务的基础。
namespace-命名空间。
xmlns=“http://yhd.cn” 使用默认命名空间。
xmlns:yhd=“http://yhd.cn”使用指定名称的命名空间。
名词2:WSDL – WebService Description Language – Web服务描述语言。
通过XML形式说明服务在什么地方-地址。
名词3:SOAP-Simple Object Access Protocol(简单对象访问协议)
SOAP = 在HTTP的基础上+XML[Y1] 数据。 - H TTP[Y2]
SOAP是基于HTTP的。
SOAP的组成如下:
Envelope – 必须的部分。以XML的根元素出现。
Headers – 可选的。
Body – 必须的。在body部分,包含要执行的服务器的方法。和发送到服务器的数据。
由于xml规范。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。