Java調(diào)用WebService接口的方法
更新時間:2015年01月29日 11:19:11 作者:靜水流深
這篇文章主要介紹了Java調(diào)用WebService接口的方法,實例分析了有參方法Add的使用技巧,需要的朋友可以參考下
本文實例講述了Java調(diào)用WebService接口的方法。分享給大家供大家參考。具體如下:
這里講述有參方法Add,代碼如下:
復制代碼 代碼如下:
public static void addTest() {
try ...{
Integer i = 1;
Integer j = 2;
//WebService URL
String service_url = "http://localhost:4079/ws/Service.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));
//設置要調(diào)用的方法
call.setOperationName(new QName("http://www.dbjr.com.cn/T", "Add"));
//該方法需要的參數(shù)
call.addParameter("a", org.apache.axis.encoding.XMLType.XSD_INT,
javax.xml.rpc.ParameterMode.IN);
call.addParameter("b", org.apache.axis.encoding.XMLType.XSD_INT,
javax.xml.rpc.ParameterMode.IN);
//方法的返回值類型
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.dbjr.com.cn/Add");
//調(diào)用該方法
Integer res = (Integer)call.invoke(
new Object[]...{
i, j
}
);
System.out.println( "Result: " + res.toString());
} catch (Exception e) ...{
System.err.println(e);
}
}
try ...{
Integer i = 1;
Integer j = 2;
//WebService URL
String service_url = "http://localhost:4079/ws/Service.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));
//設置要調(diào)用的方法
call.setOperationName(new QName("http://www.dbjr.com.cn/T", "Add"));
//該方法需要的參數(shù)
call.addParameter("a", org.apache.axis.encoding.XMLType.XSD_INT,
javax.xml.rpc.ParameterMode.IN);
call.addParameter("b", org.apache.axis.encoding.XMLType.XSD_INT,
javax.xml.rpc.ParameterMode.IN);
//方法的返回值類型
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.dbjr.com.cn/Add");
//調(diào)用該方法
Integer res = (Integer)call.invoke(
new Object[]...{
i, j
}
);
System.out.println( "Result: " + res.toString());
} catch (Exception e) ...{
System.err.println(e);
}
}
運行,結果返回:Result:3
希望本文所述對大家的Java程序設計有所幫助。
相關文章
SpringBoot Redis配置多數(shù)據(jù)源的項目實踐
springboot中默認的redis配置是只能對單個redis庫進行操作的, 那么我們需要多個庫操作的時候這個時候就可以采用redis多數(shù)據(jù)源 ,本文就介紹了SpringBoot Redis配置多數(shù)據(jù)源,感興趣的可以了解一下2023-07-07IntelliJ IDEA中SpringBoot項目通過devtools實現(xiàn)熱部署的方法
這篇文章主要介紹了IntelliJ IDEA中SpringBoot項目通過devtools實現(xiàn)熱部署的方法,本文分步驟給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-08-08解決@RequestBody接收json對象報錯415的問題
這篇文章主要介紹了解決@RequestBody接收json對象報錯415的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06Java使用jdbc連接實現(xiàn)對MySQL增刪改查操作的全過程
JDBC的全稱是Java?Database?Connectivity,即Java數(shù)據(jù)庫連接,它是一種可以執(zhí)行SQL語句的Java?API,下面這篇文章主要給大家介紹了關于Java使用jdbc連接實現(xiàn)對MySQL增刪改查操作的相關資料,需要的朋友可以參考下2023-03-03