java調(diào)用webservice的.asmx接口的使用步驟
前言
接觸到一個(gè).asmx結(jié)尾的webservice接口,為了增加記憶決定記錄下來。
一、接口類型
已.asmx結(jié)尾的接口
例:接口地址:http://IP地址/xxx/service/xxx/xxxx.asmx 方法名:test 參數(shù)類型:string
二、使用步驟
1.訪問方式
代碼如下(示例):
controller類:
String s = clientUtil.test("http://IP地址/xxx/service/xxx/xxxx.asmx", "test","test");
調(diào)用類:
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);
// 設(shè)置要調(diào)用哪個(gè)方法
call.setOperationName(new QName(soapaction, methodName));
// 設(shè)置要傳遞的參數(shù)名
call.addParameter(new QName(soapaction,"str"),org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
// 提供標(biāo)準(zhǔn)類型 有addParameter就必須有setReturnType
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapaction + methodName);
// 調(diào)用方法并傳遞參數(shù)
ref = (String) call.invoke(new Object[]{str});
return ref;
} catch (Exception e) {
e.printStackTrace();
}
return ref;
}
2.導(dǎo)入的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
到此這篇關(guān)于java調(diào)用webservice的.asmx接口的文章就介紹到這了,更多相關(guān)java調(diào)用webservice接口內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java Enum和String及int的相互轉(zhuǎn)化示例
這篇文章主要介紹了Java Enum和String及int的相互轉(zhuǎn)化示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
Java服務(wù)端架構(gòu)之微服務(wù)與單體服務(wù)的權(quán)衡方式
本文比較了Java微服務(wù)與單體服務(wù)的優(yōu)缺點(diǎn),并提供了相應(yīng)的示例代碼,微服務(wù)架構(gòu)具有可擴(kuò)展性、技術(shù)多樣性等優(yōu)勢,但復(fù)雜性和網(wǎng)絡(luò)延遲是缺點(diǎn),單體服務(wù)架構(gòu)簡單易部署,但擴(kuò)展性差,選擇哪種架構(gòu)應(yīng)根據(jù)項(xiàng)目需求和團(tuán)隊(duì)能力2025-03-03
Spring實(shí)戰(zhàn)之獲取其他Bean的屬性值操作示例
這篇文章主要介紹了Spring實(shí)戰(zhàn)之獲取其他Bean的屬性值操作,結(jié)合實(shí)例形式分析了Spring操作Bean屬性值的相關(guān)配置與實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-12-12
Java單例模式實(shí)現(xiàn)靜態(tài)內(nèi)部類方法示例
這篇文章主要介紹了Java單例模式實(shí)現(xiàn)靜態(tài)內(nèi)部類方法示例,涉及構(gòu)造函數(shù)私有化等相關(guān)內(nèi)容,需要的朋友可以了解下。2017-09-09
Java ArrayList.add 的實(shí)現(xiàn)方法
這篇文章主要介紹了Java ArrayList.add 的實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11

