WebService(1-1)webservice调用
参考url : http://www.cnblogs.com/flying607/p/6254045.html
今天用动态创建客户端的方式调用webservice,报了这样一个错:
2017-01-05 20:51:46,029 DEBUG main org.apache.cxf.common.logging.LogUtils - Using org.apache.cxf.common.logging.Log4jLogger for logging.
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
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.
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'
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'
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.
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
2017-01-05 20:51:46,292 DEBUG main org.apache.cxf.transport.http.Headers - Accept: */*
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.
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
2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Content length: -1
2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Header fields:
null: [HTTP/1.1 200 OK]
Date: [Thu, 05 Jan 2017 12:51:46 GMT]
Transfer-Encoding: [chunked]
Content-Type: [text/xml]
Server: [Apache-Coyote/1.1] Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy15.bind(Unknown Source)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:318)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
at platform.AnotherWSTest.main(AnotherWSTest.java:12)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:53)
... 6 more
Caused by: java.lang.NoSuchFieldError: theInstance
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:165)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:112)
at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:415)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:246)
... 11 more
服务端是没有问题的,用url调用可以正常执行。
最后通过更改我们的CXF版本解决了这个问题:
之前的版本:2.6.2
修改后的版本:2.7.18,试了用3.X.X表示不行
因为是用的maven所以该版本比较方便,如下:
常量
<properties>
<cxf.version>2.7.18</cxf.version>
</properties>
dependency
<!-- CXF WEBSERVICE -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- CXF WEBSERVICE END -->
服务端和客户端最好统一,如果只改客户端(cxf-rt-frontend-jaxws)为2.7.18也是可以的
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import com.alibaba.fastjson.JSON; import javax.xml.bind.*; /**
* @ClassName: WebServiceTest
* @Description: TODO
* @author: liuyx
* @date: 2015年9月27日下午5:22:15
*/
public class WebServiceTest {
private static final String testUrl = "http://172.16.10.87/platform3.0/webService/TestWebservice?wsdl";
public static void main(String[] args) throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(testUrl); Object[] objects=client.invoke("testOut", "test");
//输出调用结果
System.out.println(JSON.toJSONString(objects));
}
}
WebService(1-1)webservice调用的更多相关文章
- WebService学习总结(四)——调用第三方提供的webService服务
http://www.cnblogs.com/xdp-gacl/p/4260627.html 互联网上面有很多的免费webService服务,我们可以调用这些免费的WebService服务,将一些其他 ...
- CXF发布webService服务以及客户端调用
这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...
- loadrunner做webservice接口之简单调用
今天听大神讲了webservice做接口,我按照他大概讲的意思自己模拟实战了下,可能还有很多不对,一般使用webservice做接口,会使用到soapui,但是用了loadrunner以后发现lr很快 ...
- Java WebService接口生成和调用 图文详解>【转】【待调整】
webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...
- java Webservice(一)HttpClient远程调用
我们将Web Service发布在Tomcat或者其他应用服务器上后,有很多方法可以调用该Web Service,常用的有两种: 1.通过浏览器HTTP调用,返回规范的XML文件内容 2.通 ...
- c# WebService SOAP及Rest调用
SOAP及Rest的调用区别参照如下: REST似乎在一夜间兴起了,这可能引起一些争议,反对者可以说REST是WEB诞生之始甚而是HTTP出现之日就相伴而生的原则.但是毋庸置疑的事实是,在Google ...
- SOAP Webservice和RESTful Webservice
http://blog.sina.com.cn/s/blog_493a845501012566.html REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的 ...
- Restful是什么,SOAP Webservice和RESTful Webservice
首先,应该怀着这样一种心态来学习Restful——Restful你可以将其理解一种软件架构风格,并且诠释了Http协议的设计初衷,所以不要把他理解的那么神秘,Restful风格有好处,当然也是有坏处的 ...
- Web Service进阶(七)浅谈SOAP Webservice和RESTful Webservice
浅谈SOAP Webservice和RESTful Webservice REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩性.RE ...
- Webservice服务创建、调用笔记
引言 以前使用windows服务,于是学习并记录下来:windows服务的创建.安装.调试全过程及引发的后续学习.现如今需要用到webservice,对此感觉到很困惑.经过几天的学习.查阅资料,终于大 ...
随机推荐
- form + iframe 获取表单提交后返回的数据
原理: submit 提交表单没有回调函数,但是可以用iframe来接收返回结果,最后进行格式转换就ok了: 原文地址: http://blog.csdn.net/simeng_1016/articl ...
- 使用Angular CLI生成路由
第一篇文章是: "使用angular cli生成angular5项目" : http://www.cnblogs.com/cgzl/p/8594571.html 第二篇文章是: & ...
- HashMap源码解析(JDK1.8)
package java.util; import sun.misc.SharedSecrets; import java.io.IOException; import java.io.Invalid ...
- jquery datatable ajax配置详解
我写的这个东西类似于个人笔记,如果你想要完整的而了解 可以去这里看看 http://dt.thxopen.com/ 包括英文原网站都不错. 通过配置ajax的属性和服务器交互 $("sele ...
- css3图片模糊过滤特效
体验效果:点击这里查看效果 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- [COGS 2583]南极科考旅行
2583. 南极科考旅行 ★★ 输入文件:BitonicTour.in 输出文件:BitonicTour.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 小美要 ...
- C语言第0次作业
一.你认为大学的学习生活.同学关系.师生应该是怎样的? (1)学习生活:首先大学的学习生活应该是充实的,尽量做到时时有事做.每天有计划的学习.生活.华尔街有一位名叫罗伊.R.纽伯格的投资大师,他每天早 ...
- 2017-2018-1 20155306 mypwd的实现
2017-2018-1 20155306 mypwd的实现 一.pwd的使用 功能: Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 命令格式:pwd [选项] 命 ...
- PTA題目的處理(二)
題目7-1 計算分段函數[1] 1.實驗代碼 #include <stdio.h> int main() { float x,y; scanf("%f",&x) ...
- C简单实现动态顺序表
<span style="font-size:18px;">一下为简单实现:</span> #define SIZE 3; typedef int Data ...