導航:首頁 > 配伺服器 > axis客戶端如何引用伺服器端的類

axis客戶端如何引用伺服器端的類

發布時間:2024-05-30 04:48:17

java怎麼使用axis調用webservice

方式一:生成客戶端代碼調用方式。
通過插件工具生成客戶端代碼進行調用。例如:存在一服務為 http://127.0.0.1:8000/axis2/services/SMSSendService?wsdl通過插件可以生成SMSSendServiceStub.Java和SMSSendServiceCallbackHandler.java類。調用的客戶端代碼如:

try {

SMSSendServiceStub stub=new SMSSendServiceStub();

SMSSendServiceStub.method1 m1=new SMSSendServiceStub.method1();
m1.setParam1("xxx");

try {
String ret=stub.multiSend(m1).get_return();
System.out.print(ret);
} catch (RemoteException e) {
e.printStackTrace();
}
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
方式二:使用axis2.rpc.client.RPCServiceClient方式調用。

調用的代碼簡單舉例如下:

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
......

try {

final String endpoint = "http://127.0.0.1:8000/axis2/services/SMSSendService";
String opName = "method1";
String param="xxx";
Object[] opArgs = new Object[] { param };
Class<?>[] opReturnType = new Class[] { String[].class };

RPCServiceClient serviceClient = new RPCServiceClient();//此處RPCServiceClient 對象實例建議定義成類中的static變數,否則多次調用會出現連接超時的錯誤。

Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(endpoint);
options.setTo(targetEPR);
QName opQName = new QName("http://service.ws.sms.ipcc.ydtf.com",
opName);
Object[] ret = serviceClient.invokeBlocking(opQName, opArgs,
opReturnType);
System.out.println(((String[]) ret[0])[0]);
} catch (AxisFault e) {
e.printStackTrace();
}

閱讀全文

與axis客戶端如何引用伺服器端的類相關的資料

熱點內容
北漂程序員出車禍 瀏覽:914
亞馬遜為什麼用雲端伺服器 瀏覽:65
程序員審核職位 瀏覽:385
德龍空調壓縮機 瀏覽:780
紅旗app如何注冊新賬戶 瀏覽:360
慣導pdf 瀏覽:606
c程序員的平均工資 瀏覽:58
微小店源碼 瀏覽:801
編譯原理答題題庫 瀏覽:169
ubuntu編程入門 瀏覽:301
antbuild命令 瀏覽:771
怎麼訂閱伺服器 瀏覽:593
視頻專用加密器哪個好用 瀏覽:295
app無法使用網路哪裡設置 瀏覽:847
紅旗linux怎麼安裝 瀏覽:136
各種破車窗工具測試解壓 瀏覽:933
優格手錶app如何使用 瀏覽:716
docker進入容器命令 瀏覽:498
先河私有雲伺服器價格 瀏覽:459
java字體代碼 瀏覽:829