这篇文章将为大家详细讲解有关Java如何调用webservice的.asmx接口,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
接触到一个.asmx结尾的webservice接口,为了增加记忆决定记录下来。
已.asmx结尾的接口
例:接口地址:http://IP地址/xxx/service/xxx/xxxx.asmx
方法名:test
参数类型:string
代码如下(示例):
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;
}
如下:
<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>
关于Java如何调用webservice的.asmx接口就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。