java调用webservice的.asmx接口的使用步骤
更新时间:2021年09月09日 14:59:32 作者:很少更新
这篇文章主要介绍了java调用webservice的.asmx接口的使用步骤,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
前言
接触到一个.asmx结尾的webservice接口,为了增加记忆决定记录下来。
一、接口类型
已.asmx结尾的接口
例:接口地址:http://IP地址/xxx/service/xxx/xxxx.asmx 方法名:test 参数类型:string
二、使用步骤
1.访问方式
代码如下(示例):
controller类:
String s = clientUtil.test("http://IP地址/xxx/service/xxx/xxxx.asmx", "test","test");
调用类:
public static String test(String Url, String methodName, String str) throws Exception { String ref = null; // webService链接地址 String url = Url; //获取域名地址,server定义的 String soapaction = "http://tempuri.org/"; Service service = new Service(); try { Call call = (Call) service.createCall(); call.setTargetEndpointAddress(url); // 设置要调用哪个方法 call.setOperationName(new QName(soapaction, methodName)); // 设置要传递的参数名 call.addParameter(new QName(soapaction,"str"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); // 提供标准类型 有addParameter就必须有setReturnType call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); call.setUseSOAPAction(true); call.setSOAPActionURI(soapaction + methodName); // 调用方法并传递参数 ref = (String) call.invoke(new Object[]{str}); return ref; } catch (Exception e) { e.printStackTrace(); } return ref; }
2.导入的maven
如下:
<dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>axis</groupId> <artifactId>axis-jaxrpc</artifactId> <version>1.4</version> </dependency>
参考:
[1]https://blog.csdn.net/qq_34302802/article/details/101197464
到此这篇关于java调用webservice的.asmx接口的文章就介绍到这了,更多相关java调用webservice接口内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Java调度线程池ScheduledThreadPoolExecutor不执行问题分析
最近项目上反馈某个重要的定时任务突然不执行了,很头疼,开发环境和测试环境都没有出现过这个问题。定时任务采用的是ScheduledThreadPoolExecutor,后来一看代码发现踩了一个大坑。本文就来和大家聊聊这次的踩坑记录与解决方法,需要的可以参考一下2023-03-03SpringBoot如何使用RequestBodyAdvice进行统一参数处理
这篇文章主要介绍了SpringBoot使用RequestBodyAdvice进行统一参数处理方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-06-06spring boot与spring mvc的区别及功能介绍
这篇文章主要介绍了spring boot与spring mvc的区别是什么以及spring boot和spring mvc功能介绍,感兴趣的朋友一起看看吧2018-02-02
最新评论