微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CXF调用WebService通用类

一个CXF动态调用WebService的例子,主要使用了CXF动态创建客户端的功能,需要导入的包:cxf-2.3.2.jar、neethi-2.0.4.jar、wsdl4j-1.6.2.jar、XmlSchema-1.4.7.jar。

调用列子:

  1. String str = WebServiceClientHelper.callService("http://www.xxxx.cn/services/Test?wsdl","queryProfile",255)">"12345");
  2. out.println(str);

通用类代码:

package cn.org.cdw.util;
  •  import org.apache.cxf.endpoint.Client;
  • import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicclientFactory;
  •  /**
  • * @author chendw
  • * @Description: WebService客户端通用类
  • */
  • public class WebServiceClientHelper {
  • * @Title: callService
  • * @Description: 调用远程的webservice并返回数据
  • * @param wsUrl
  • *            ws地址
  • * @param method
  • *            调用的ws方法
  • * @param arg
  • *            参数
  • * @return
  • * @return:String
  • * @throws
  • */
  • static String callService(String wsUrl, String method, Object...arg) {
  • JaxWsDynamicclientFactory dcf = JaxWsDynamicclientFactory.newInstance();
  • Client client = dcf.createClient(wsUrl);
  • Object[] res = null;
  • try {
  • res = client.invoke(method, arg);
  • catch (Exception e) {
  • e.printstacktrace();
  • }
  • return (String) res[0];
  • }
  • 版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

    相关推荐