根据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  ,保存退出

115411_vnJh_167900.jpg

        3. cmd 一下 看是否有此界面,如果有则成功了

120003_mgdT_167900.jpg

        4. 启动 soapui-4.5.2\bin\soapui.bat , 新建 New soapUI project

125650_FFWm_167900.jpg

5. 点ok 后, 生成如下图,然后选中项目选择apache cxf 

131933_vdEw_167900.jpg

6. 点击tools,选中cxf 路径,ok后,在右边矿 选择输出文件路径,填写包路径,勾选 生成 generates client ,generates server, generates implement, 点击generates 

135355_HW4A_167900.jpg

135356_hfEm_167900.jpg

7. 这就完成了。其实soapUI 也只是用apache-cxf 命令生成。也可以用apache-cxf bin 下生成目录.


135738_YN45_167900.jpg


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" />
</beans>


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>
	  <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 

按上面来不会有错误. 在浏览器输入 http://localhost:8080/tsmweb/services/sptsmstubws?wsdl

路径名称 servlet url pattern  + applicationContext-cxf.xml address

显示如下。成功

141310_fp9A_167900.jpg



转载于:https://my.oschina.net/hlevel/blog/281026

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值