java动态调用webservice
cxf方式
public static Object[] invokeRemoteMethod(String url, String method, Object[] parameters) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
if (!url.endsWith("wsdl")) {
url += "?wsdl";
}
org.apache.cxf.endpoint.Client client = dcf.createClient(url);
try {
Object[] objects = client.invoke(method, parameters);
return objects;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
maven引用
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-core -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.5</version>
</dependency>
缺点是效率低,调用速度慢
Xfire方式调用
public static String getData(String wsUrl, String invoke, Object[] objParams) throws MalformedURLException, Exception {
URL url = new URL(wsUrl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
Client client = new Client(connection.getInputStream(), (Class)null);
client.setProperty("disable-keep-alive", "true");
client.setProperty("disable.expect-continue", "true");
client.setUrl(wsUrl);
Object[] result = client.invoke(invoke, objParams);
String resultStr = result[0].toString();
return "".equals(resultStr)?"":resultStr;
}
maven引用
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-all</artifactId>
<version>${xfire.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
缺点是jar包太旧了,很容易与其他包冲突
java动态调用webservice的更多相关文章
- Java动态调用webService,axis2动态调用webService
Java动态调用webService axis2动态调用webService >>>>>>>>>>>>>>>& ...
- Atitit 动态调用webservice与客户端代理方式调用
Atitit 动态调用webservice与客户端代理方式调用 方式1: 使用call.invoke 直接调用WSDL,缺点:麻烦,不推荐--特别是JAVA调用.NET的WS时,会有不少的问题需要解 ...
- 动态调用WebService(C#) (非常实用)
通常我们在程序中需要调用WebService时,都是通过“添加Web引用”,让VS.NET环境来为我们生成服务代理,然后调用对应的Web服务.这样是使工作简单了,但是却和提供Web服务的URL.方法名 ...
- 动态调用webservice(部分转载)
动态调用webservice,做个笔记: public class WSHelper { /// < summary> /// 动态调用web服务 /// < /summary> ...
- C# 动态调用webservice
最近项目中,用到动态调用webservice的内容,此处记录下来,留着以后COPY(我们只需要在XML,config文件,或者数据库中配置webservice连接地址和方法名即可使用): using ...
- 动态调用webservice及WCF服务
动态调用web服务,该方法只针对Web service, WCF的服务不行,如果是WCF的就通过工具直接生产代理类,把代理类配置到调用的项目中,通过配置客户端的终结点动态的取实现: 通过Svcutil ...
- C# .NET 动态调用webservice的三种方式
转载自 百度文库 http://wenku.baidu.com/link?url=Q2q50wohf5W6UX44zqotXFEe_XOMaib4UtI3BigaNwipOHKNETloMF4ax4W ...
- WebService – 2.动态调用WebService
在本节课程中,将演示如何通过程序动态添加.调用.编译.执行WebService并返回结果. WebService动态调用示意图 WebService相关知识 代码文档对象模型CodeDom的使用 编程 ...
- 用C#通过反射实现动态调用WebService 告别Web引用
我们都知道,调用WebService可以在工程中对WebService地址进行WEB引用,但是这确实很不方便.我想能够利用配置文件灵活调用WebService.如何实现呢? 用C#通过反射实现动态调用 ...
随机推荐
- 如何利用git由本机向github上传文件
首先,下载一个git,安装. 安装成功之后,输入以下命令,引号内的为你自己的名字和邮箱git config --global user.name "Your Name"git co ...
- jQuery Mobile入门
转:http://www.cnblogs.com/linjiqin/archive/2011/07/17/2108896.html 简介:jQuery Mobile框架可以轻松的帮助我们实现非常好看的 ...
- POJ 1149 PIGS
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20579 Accepted: 9387 Description ...
- js 正则表达式 ( 1 )
https://regexper.com/ 量词: ?: 最多一次(0次或者1次) +:至少一次(大于等于1次) *:大于等于0次 {n}:n次 {n,m}:n次到m次之间,包括n,m {n,}:n次 ...
- Android 千牛数据库分析
标签(空格分隔): 千牛,逆向 问题:Android 千牛登陆后产生保存用户数据的db无法直接用sqlite3打开,需要解密. 反编译Apk后jd-gui查看源码.熟悉的sqlcrypto模块加密,阿 ...
- 火车头采集ecshop 文章接口文件
<?php header("Content-Type:text/html;charset=utf-8"); $host = $_SERVER['HTTP_HOST']; // ...
- PHPCMS导航栏当前栏目选中方法
{if $top_parentid==0}<!--判断首页显示的是不是首页--> <li><a href="{siteurl($siteid)}" s ...
- yii2创建数据表
原文地址: http://blog.csdn.net/xiaoyangxiaodong/article/details/45026865
- adb install INSTALL_FAILED_ALREADY_EXISTS
安装时候碰到的一个问题:已经签名的包,重新通过adb install 会提示安装错误.提示:Failure [INSTALL_FAILED_ALREADY_EXISTS] 为啥eclipse自己就可以 ...
- 第一届山东省ACM——Phone Number(java)
Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...