您的位置:首页 > 编程语言 > Java开发

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为测试工具类 

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

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring mvc cxf