如何使用Web 生成webservice服务端进行WSDL逆向生成服务端

> 博客详情
摘要: 根据wsdl 文件 用soapUi 快速创建webService 服务创建(图文并茂)
& & & 最近公司业务上使用webservice 频繁。由于之前都是自己搭建webservice 自己定义提供给别人服务,现在则相反需求都是根据人家提供的wsdl 文件来生成 我们平台需要提供的接口。刚开始不知道如何生成,为了一个webservice 服务,而搭建多种环境如: xfire,jaxws,axis,cxf , 几种都搭建起来,一种一种比较生成wsdl 的格式,最好确认了格式,又得确认方法,对象,服务名,一系列下来的花上 1-2天时间。
& & & 言归正传,首先普及一下,webservice 规范,&无论它们所使用的语言、 平台或内部协议是什么, 都可以相互交换数据。
换句话说,人家提供的wsdl ,我们生成的基本条件为 调用的服务名,端口,方法名得和 提供的wsdl 一致,这样才能通讯. 所以不必纠结使用那个框架 生成,选我们最熟悉的webservice ,这里我使用的是&apache-cxf-2.7.11
&&&&&&&&生成 根据人家提供的wsdl 一样的接口与服务 , 测试服务接口软件&soapui-4.5.2 , &apache-cxf-2.7.11
&&&&&&&&1. 在官网下载 apache-cxf-2.7.11 完成后,配置环境变量(和java 配置环境变量一样)
& & & & 新建环境变量CXF_HOME = &你的路径/apache-cxf-2.7.11
& & & & 2. 在Path 后面添加 %CXF_HOME%/bin &,保存退出
& & & & 3. cmd 一下 看是否有此界面,如果有则成功了
& &&& & 4. 启动&soapui-4.5.2\bin\soapui.bat , 新建 New soapUI project
5. 点ok 后, 生成如下图,然后选中项目选择apache cxf&
6. 点击tools,选中cxf 路径,ok后,在右边矿 选择输出文件路径,填写包路径,勾选 生成 generates client ,generates server, generates implement, 点击generates&
7. 这就完成了。其实soapUI 也只是用apache-cxf 命令生成。也可以用apache-cxf bin 下生成目录.
8. 引入jar 包 ,我这里使用的是 maven&
&&&dependencies&
&dependency&
&&&&groupId&org.apache.cxf&/groupId&
&&&&artifactId&cxf-api&/artifactId&
&&&&version&2.7.11&/version&
&&&/dependency&
&&&dependency&
&&&&groupId&org.apache.cxf&/groupId&
&&&&artifactId&cxf-rt-frontend-jaxws&/artifactId&
&&&&version&2.7.11&/version&
&&&/dependency&
&&&dependency&
&&&&groupId&org.apache.cxf&/groupId&
&&&&artifactId&cxf-rt-bindings-soap&/artifactId&
&&&&version&2.7.11&/version&
&&&/dependency&
&&&dependency&
&&&&groupId&org.apache.cxf&/groupId&
&&&&artifactId&cxf-rt-transports-http&/artifactId&
&&&&version&2.7.11&/version&
&&&/dependency&
&&&dependency&
&&&&groupId&org.apache.cxf&/groupId&
&&&&artifactId&cxf-rt-ws-security&/artifactId&
&&&&version&2.7.11&/version&
&&&/dependency&
9. 复制到项目后。 新建文件名applicationContext-cxf.xml ,&
&?xml&version="1.0"&encoding="UTF-8"&standalone="no"?&&&
&beans&xmlns="http://www.springframework.org/schema/beans"&&
&&&&xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&&&
&&&&xmlns:jaxws="http://cxf.apache.org/jaxws"&&&
&&&&xmlns:context="http://www.springframework.org/schema/context"&&
&&&&xsi:schemaLocation="&&
&&&&&&&&http://www.springframework.org/schema/beans&http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&&
&&&&&&&&http://www.springframework.org/schema/context&http://www.springframework.org/schema/context/spring-context-3.0.xsd&&&
&&&&&&&&http://cxf.apache.org/jaxws&http://cxf.apache.org/schemas/jaxws.xsd"&&&
&import&resource="classpath:META-INF/cxf/cxf.xml"&/&
&import&resource="classpath:META-INF/cxf/cxf-servlet.xml"&/&
&jaxws:endpoint&
&&id="sptsmstubws"&
&&implementor="com.ishua.tsmsp.service.SptsmstubwsImpl"&
&&address="/sptsmstubws"&/&
10. 与spring 的applicationContext.xml 文件一个目录, 再在applicationContext.xml 里面引用
&?xml&version="1.0"&encoding="UTF-8"?&
&beans&xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans&http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context&http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop&http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx&http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
&import&resource="applicationContext-cxf.xml"/&
11. 在工程里配置 web.xml&
&!--cxf&webservice&--&
&&&servlet-name&CXFServlet&/servlet-name&
&&&servlet-class&org.apache.cxf.transport.servlet.CXFServlet&/servlet-class&
&/servlet&
&servlet-mapping&
&&&servlet-name&CXFServlet&/servlet-name&
&&&url-pattern&/services/*&/url-pattern&
&/servlet-mapping&
完成上面步骤之前首先你的ssh 工程得跑的起来。最少得有spring 支持。我使用的是 spring mvc + mybatis&
按上面来不会有错误. 在浏览器输入&
路径名称 servlet url pattern &+&applicationContext-cxf.xml address
显示如下。成功
”在线下联结了各位 OSCer,推广开源项目和理念,很荣幸有你的参与~
领取条件:参与过开源中国“源创会”的 OSCer 可以领取
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥WebService服务端、客户端之个人献丑篇_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
WebService服务端、客户端之个人献丑篇
&&通过wsdl协议生成客户端的代码,以及服务端生成wsdl协议.
阅读已结束,下载文档到电脑
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢鍗氬?鍒嗙被锛

我要回帖

更多关于 wsdl逆向生成服务端 的文章

 

随机推荐