zoukankan      html  css  js  c++  java
  • 根据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

    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 一下 看是否有此界面,如果有则成功了

     使用apache-cxf创建soapUI并创建webService服务

    4. 启动 soapui-4.5.2insoapui.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" />
    </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

    显示如下。成功

    引用:https://my.oschina.net/hlevel/blog/281026

  • 相关阅读:
    圣战 [奇环, 树上差分]
    花火之声不闻于耳 [线段树]
    SP2878 KNIGHTS
    P5300 [GXOI/GZOI2019]与或和 [单调栈]
    Speike [线段树, 动态规划]
    Jerry [动态规划]
    JSON对象
    正则书写
    flex布局实践
    数组对象的深拷贝与浅拷贝
  • 原文地址:https://www.cnblogs.com/kuoAT/p/6893661.html
Copyright © 2011-2022 走看看