参考url : http://www.cnblogs.com/flying607/p/6254045.html

今天用动态创建客户端的方式调用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. }

WebService(1-1)webservice调用的更多相关文章

  1. WebService学习总结(四)——调用第三方提供的webService服务

    http://www.cnblogs.com/xdp-gacl/p/4260627.html 互联网上面有很多的免费webService服务,我们可以调用这些免费的WebService服务,将一些其他 ...

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

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

  3. loadrunner做webservice接口之简单调用

    今天听大神讲了webservice做接口,我按照他大概讲的意思自己模拟实战了下,可能还有很多不对,一般使用webservice做接口,会使用到soapui,但是用了loadrunner以后发现lr很快 ...

  4. Java WebService接口生成和调用 图文详解>【转】【待调整】

    webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...

  5. java Webservice(一)HttpClient远程调用

    我们将Web Service发布在Tomcat或者其他应用服务器上后,有很多方法可以调用该Web Service,常用的有两种: 1.通过浏览器HTTP调用,返回规范的XML文件内容      2.通 ...

  6. c# WebService SOAP及Rest调用

    SOAP及Rest的调用区别参照如下: REST似乎在一夜间兴起了,这可能引起一些争议,反对者可以说REST是WEB诞生之始甚而是HTTP出现之日就相伴而生的原则.但是毋庸置疑的事实是,在Google ...

  7. SOAP Webservice和RESTful Webservice

    http://blog.sina.com.cn/s/blog_493a845501012566.html REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的 ...

  8. Restful是什么,SOAP Webservice和RESTful Webservice

    首先,应该怀着这样一种心态来学习Restful——Restful你可以将其理解一种软件架构风格,并且诠释了Http协议的设计初衷,所以不要把他理解的那么神秘,Restful风格有好处,当然也是有坏处的 ...

  9. Web Service进阶(七)浅谈SOAP Webservice和RESTful Webservice

    浅谈SOAP Webservice和RESTful Webservice REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩性.RE ...

  10. Webservice服务创建、调用笔记

    引言 以前使用windows服务,于是学习并记录下来:windows服务的创建.安装.调试全过程及引发的后续学习.现如今需要用到webservice,对此感觉到很困惑.经过几天的学习.查阅资料,终于大 ...

随机推荐

  1. P2P技术简介

    P2P技术简介 NAT( Network Address Translation)穿越(俗称打洞)技术 前言: p2p已经存在于我们生活的方方面面:我们通过下载在工具(比如迅雷,bitorent,各种 ...

  2. CucumberJS 资源

    https://cucumber.io/docs/reference/javascript https://github.com/cucumber/cucumber-js

  3. business expressions(一)

    一. 1.24/7 24/7 :twenty four hours a day, seven days a week I work 24/7.——meaing i work all the time. ...

  4. window.open打开文件乱码

    问题:刚开始使用window.open在IE兼容模式下打开文件下载出现乱码. 一开始以为是文件名是中文导致的.然后使用a标签的download属性更改文件名解决. <a class=" ...

  5. Vue自定义插件方法大全

    新年第一天首先祝大家新年快乐,心想事成! 1.利用根实例构造函数的原型 //在构造函数的原型链上添加自定义属性 Vue.prototype.test = 'pomelo' //在其他组件中调用 con ...

  6. 笔记:XML-解析文档

    要处理XML文档,就要先解析(parse)他,解析器时这样一个程序,读入一个文件,确认整个文件具有正确的格式,然后将其分解成各种元素,使得程序员能够访问这些元素,Java库提供了两种XML解析器: 像 ...

  7. 【Flask】 利用uWSGI和Nginx发布Flask应用

    因为Flask比较容易上手,之前也拿flask写过几个小项目,不过当时天真地以为只要在服务器上nohup跑一个python脚本就算是成功发布了这个flask项目.实际上这还面临很多问题,比如并发性不好 ...

  8. 【Linux】 CentOS6.5安装Python2.7以及pip等工具

    原文地址 CentOS6.5下是原来就有python的,我的镜像里面自带的python版本是2.6.6.如果想要自己更新一个更加新的python版本可以这么做: 安装python2.7安装包. 从官网 ...

  9. mysql错误集锦

    1.使用myqldump备份出错:(--opt快速导出) mysqldump -u root -p --database mysql --opt -h127.0.0.1 > mysql.sqlE ...

  10. jQuery中ajax方法无法执行回调函数问题

    最近遇到一个问题,发现使用jquery的ajax方法时,回调方法无法执行,而使用$.load()方法时却能正确返回数据.经过长时间调试最终发现是自己粗心大意,原来后台返回的是json数据,而返回的数据 ...