今天用动态创建客户端的方式调用webservice,报了这样一个错:

  1. 2017-01-05 20:51:46,029 DEBUG main org.apache.cxf.common.logging.LogUtils - Using org.apache.cxf.common.logging.Log4jLogger for logging.
  2. 2017-01-05 20:51:46,168 DEBUG main org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Creating client from WSDL http://localhost/sdas/webService/TestWebservice?wsdl
  3. 2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been (re)configured for plain http.
  4. 2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - No Trust Decider configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'
  5. 2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - No Auth Supplier configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'
  6. 2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been configured for plain http.
  7. 2017-01-05 20:51:46,277 DEBUG main org.apache.cxf.transport.http.HTTPConduit - registering incoming observer: org.apache.cxf.transport.TransportURIResolver$1@6165e7a5
  8. 2017-01-05 20:51:46,292 DEBUG main org.apache.cxf.transport.http.Headers - Accept: */*
  9. 2017-01-05 20:51:46,294 DEBUG main org.apache.cxf.transport.http.TrustDecisionUtil - No Trust Decider for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'. An afirmative Trust Decision is assumed.
  10. 2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Response Code: 200 Conduit: {http://cxf.apache.org}TransportURIResolver.http-conduit
  11. 2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Content length: -1
  12. 2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Header fields:
  13. null: [HTTP/1.1 200 OK]
  14. Date: [Thu, 05 Jan 2017 12:51:46 GMT]
  15. Transfer-Encoding: [chunked]
  16. Content-Type: [text/xml]
  17. Server: [Apache-Coyote/1.1]
  18.  
  19. Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
  20. at com.sun.proxy.$Proxy15.bind(Unknown Source)
  21. at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:318)
  22. at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
  23. at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
  24. at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
  25. at platform.AnotherWSTest.main(AnotherWSTest.java:12)
  26. Caused by: java.lang.reflect.InvocationTargetException
  27. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  28. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  29. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  30. at java.lang.reflect.Method.invoke(Method.java:606)
  31. at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:53)
  32. ... 6 more
  33. Caused by: java.lang.NoSuchFieldError: theInstance
  34. at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:165)
  35. at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:112)
  36. at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:415)
  37. at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:246)
  38. ... 11 more

服务端是没有问题的,用url调用可以正常执行。

最后通过更改我们的CXF版本解决了这个问题:

之前的版本:2.6.2

修改后的版本:2.7.18,试了用3.X.X表示不行

因为是用的maven所以该版本比较方便,如下:

常量

  1. <properties>
  2. <cxf.version>2.7.18</cxf.version>
  3. </properties>

dependency

  1. <!-- CXF WEBSERVICE -->
  2. <dependency>
  3. <groupId>org.apache.cxf</groupId>
  4. <artifactId>cxf-rt-frontend-jaxws</artifactId>
  5. <version>${cxf.version}</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.apache.cxf</groupId>
  9. <artifactId>cxf-rt-transports-http</artifactId>
  10. <version>${cxf.version}</version>
  11. </dependency>
  12. <!-- CXF WEBSERVICE END -->

服务端和客户端最好统一,如果只改客户端(cxf-rt-frontend-jaxws)为2.7.18也是可以的

最后附一个动态调用示例写法:

  1. import org.apache.cxf.endpoint.Client;
  2. import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
  3.  
  4. import com.alibaba.fastjson.JSON;
  5.  
  6. import javax.xml.bind.*;
  7.  
  8. /**
  9. * @ClassName: WebServiceTest
  10. * @Description: TODO
  11. * @author: liuyx
  12. * @date: 2015年9月27日下午5:22:15
  13. */
  14. public class WebServiceTest {
  15. private static final String testUrl = "http://172.16.10.87/platform3.0/webService/TestWebservice?wsdl";
  16. public static void main(String[] args) throws Exception {
  17. JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
  18. Client client = dcf.createClient(testUrl);
  19.  
  20. Object[] objects=client.invoke("testOut", "test");
  21. //输出调用结果
  22. System.out.println(JSON.toJSONString(objects));
  23. }
  24. }

CXF 调用方式——动态创建客户端(调用稳定版本号为2.7.18)的更多相关文章

  1. CXF 动态创建客户端调用稳定版本号为2.7.18

    今天用动态创建客户端的方式调用webservice,报了这样一个错: 2017-01-05 20:51:46,029 DEBUG main org.apache.cxf.common.logging. ...

  2. CXF发布webService服务以及客户端调用

    这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...

  3. WebService—CXF—实现接口发布和客户端调用

    (一)接口发布的几种方式 定义接口: @WebService(targetNamespace="http://www.itfad.net/queryUser") public in ...

  4. Spring集成CXF发布WebService并在客户端调用

    Spring集成CXF发布WebService 1.导入jar包 因为官方下载的包里面有其他版本的sprring包,全导入会产生版本冲突,所以去掉spring的部分,然后在项目根目录下新建了一个CXF ...

  5. WCF 动态调用(动态创建实例接口)

    很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; usin ...

  6. firedac的TFDStoredProc动态创建并调用存储过程

    1)中间件执行存储过程 sp.Close; sp.StoredProcName := procName; sp.Prepare;  // 生成存储过程的参数列表,无任何OUTPUT的存储过程,也会自动 ...

  7. cxf 动态创建客户端,局域网能正常调用服务端,外网不能访问

  8. Live555 中的客户端动态库.so的调用方式之一 程序中调用

    1.  打开动态链接库:    #include <dlfcn.h>    void *dlopen(const char *filename, int flag);    该函数返回操作 ...

  9. Web Service基础——四种客户端调用方式

    通过访问公网服务地址 http://www.webxml.com.cn/zh_cn/index.aspx 来演示四种不同的客户端调用方式 1. 生成客户端调用方式 1.1 Wsimport命令介绍 首 ...

随机推荐

  1. [BZOJ4832]抵制克苏恩(概率期望DP)

    方法一:倒推,最常规的期望DP.f[i][a][b][c]表示还要再攻击k次,目前三种随从个数分别为a,b,c的期望攻击英雄次数,直接转移即可. #include<cstdio> #inc ...

  2. 【DFS】Gym - 100781A - Adjoin the Networks

    给你一个森林,让你把它连接成一颗树,使得直径最小. 就求出每颗树的重心以后,全都往直径最大的那个的重心上连,一般情况是最大/2+次大/2+1,次大/2+第三大/2+2 中取较大者. 还有些特殊情况要特 ...

  3. #iOS问题记录# UITextview富文本链接,禁止长按事件

    UITextView的富文本组装,添加图片点击事件,启动 - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *) ...

  4. NHibernate 之持久化类、拦截器 (第二篇)

    一.持久化类中成员标量的要求 作为被NHibernate使用的持久化类,必须满足以下几点要求: 1.声明读写属性 在NHibernate的使用中,持久化类的成员变量必须声明对应的属性,NHiberna ...

  5. node.js+mysql把数据显示到前端简单实例

    原以为数据查出来了,要展示是鸡毛蒜皮的事儿!谁知道,我弄了一天....我错就错在没把connection.query里面. 下面的例子是可以的了! 看过我之前文章的同学,应该很熟悉下面的代码,对!主要 ...

  6. express和json的调用

    在express工程里,建立app.js var express = require('express'); var app = express(); //数据接口 var newsdata=[{ ' ...

  7. latex不能识别eps图片

    latex中可以使用.eps的图片,许多文档都介绍了怎么引用这种格式的图片,但没有给出使用过程中的注意事项.我在使用MIKTEX的时候,latex文档中引入.eps图片遇到了这样的问题.编译的时候显示 ...

  8. SqlServer数据库1433端口问题1

    在本地使用telnet ip  1433 命令测试数据库1433端口是否打开,总是提示错误,根据网上查找资料总结了如下两点思路供参考,欢迎指正! (1)第一种情况可能是"Telnet客户端& ...

  9. unity color space 选取

    https://unity3d.com/cn/learn/tutorials/topics/graphics/choosing-color-space https://docs.unity3d.com ...

  10. idea autoscroll from source