Spring+CXF3.1.3-WSDL2JAVA 搭建SOAP客户端(二)
2015-10-27 17:32
671 查看
通过CXF提供的wsdl2java工具生成客户端代码,生成的客户端代码中带有测试工具类,可以直接使用进行代码调试,方法类似于jdk自带的wsipmort命令。
使用的前提是需要下载CXF jar文件,本文以apache-cxf-3.1.3版本进行客户端代码生成。
1. wsdl2java 环境配置(使用命令前必须的环境变量配置)
CXF_HOME = D:\apache-cxf-3.1.3
CLASSPATH = %CXF_HOME%\lib
PATH = %CXF_HOME%\bin
2. 验证配置是否成功(打印CXF版本就说明配置OK)
3. 使用命令生成客户端代码
命令解释:
-d: 指定代码生成到本地的路径,“webClient”文件夹需提前创建好
-p: 指定客户端代码生成的包号(com.cxf.service.webclient)
-client:指定服务器wsdl地址
4. 将生成的客户端代码复制到项目中
5. IBaseWebService_BaseWebServiceImpPort_Client为测试工具类
6. 运行得到测试结果
源代码下载地址:http://download.csdn.net/detail/onepersontz/9217885
使用的前提是需要下载CXF jar文件,本文以apache-cxf-3.1.3版本进行客户端代码生成。
1. wsdl2java 环境配置(使用命令前必须的环境变量配置)
CXF_HOME = D:\apache-cxf-3.1.3
CLASSPATH = %CXF_HOME%\lib
PATH = %CXF_HOME%\bin
2. 验证配置是否成功(打印CXF版本就说明配置OK)
3. 使用命令生成客户端代码
命令解释:
-d: 指定代码生成到本地的路径,“webClient”文件夹需提前创建好
-p: 指定客户端代码生成的包号(com.cxf.service.webclient)
-client:指定服务器wsdl地址
4. 将生成的客户端代码复制到项目中
5. IBaseWebService_BaseWebServiceImpPort_Client为测试工具类
package com.cxf.service.webclient; /** * Please modify this class to meet your needs * This class is not complete */ import java.io.File; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.jws.WebMethod; import javax.jws.WebResult; import javax.jws.WebService; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.ws.RequestWrapper; import javax.xml.ws.ResponseWrapper; /** * This class was generated by Apache CXF 3.1.3 * 2015-10-27T17:09:33.167+08:00 * Generated source version: 3.1.3 * */ public final class IBaseWebService_BaseWebServiceImpPort_Client { private static final QName SERVICE_NAME = new QName("http://imp.service.cxf.com/", "Hello"); private IBaseWebService_BaseWebServiceImpPort_Client() { } public static void main(String args[]) throws java.lang.Exception { URL wsdlURL = Hello.WSDL_LOCATION; if (args.length > 0 && args[0] != null && !"".equals(args[0])) { File wsdlFile = new File(args[0]); try { if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURI().toURL(); } else { wsdlURL = new URL(args[0]); } } catch (MalformedURLException e) { e.printStackTrace(); } } Hello ss = new Hello(wsdlURL, SERVICE_NAME); IBaseWebService port = ss.getBaseWebServiceImpPort(); { System.out.println("Invoking helloWorld..."); java.lang.String _helloWorld__return = port.helloWorld(); System.out.println("helloWorld.result=" + _helloWorld__return); } System.exit(0); } }
6. 运行得到测试结果
源代码下载地址:http://download.csdn.net/detail/onepersontz/9217885
相关文章推荐
- android调用web service(cxf)实例应用详解
- CXF+Spring+Maven+JBOSS7简单例子
- CXF 生成客户端报错 Two classes have the same XML type ...
- cxf spring mybiats
- Web Service的CXF实现(Spring整合方式)
- 新手初识webservice-理论篇
- 新手初识webservice-实践篇
- Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务
- Web Service 那点事儿(4)—— 使用 CXF 开发 REST 服务
- Spring整合Dwr,Cannot locate BeanDefinitionParser for element [annotation-scan]
- Apache CXF REST example
- spring3 MVC手工搭建Spring3项目demo
- cxf 拦截器
- xfire客户端连接cxf服务端完全解决!
- spring mvc 开发需要的jar包的用途详解
- 基于注解的 Spring MVC 简单入门-网摘
- [MVC] 深入浅出Spring MVC
- CXF+Spring+REST发布webservice服务
- Spring和Apache CXF,ActiveMQ整合记录
- Spring MVC 为例,从前台—>后台—>前台的编解码过程及出现乱码的案例