Axis2 客戶端調用 設置超時時間


我用的是axis2-1.6.2版本。請看下面的客戶端代碼:

import org.apache.axis2.client.Options;

import com.ctis.ta.service.impl.OpenAccountForUnitServiceStub;
import com.ctis.ta.service.impl.OpenAccountForUnitServiceStub.OpenAndCheck;
import com.ctis.ta.service.impl.OpenAccountForUnitServiceStub.OpenAndCheckResponse;

public class Main {

public static void main(String[] args) throws Exception {
//OpenAccountForUnitServiceStub 是Axis2工具自動生成的類
OpenAccountForUnitServiceStub stub = new OpenAccountForUnitServiceStub();
OpenAndCheck openAndCheck = new OpenAndCheck();//openAndCheck 是服務端的方法
openAndCheck.setAddress("");//設置服務端方法OpenAndCheck()的參數值

Options options = stub._getServiceClient().getOptions();
options.setTimeOutInMilliSeconds(3);//設置超時(單位是毫秒)
stub._getServiceClient().setOptions(options);

OpenAndCheckResponse response = stub.openAndCheck(openAndCheck);//開始調用服務端的方法openAndCheck
String[] ret = response.get_return();//服務端返回一個數組
System.out.println(ret.length);
}

}

 

如果上面設置不生效,有可能是你的版本舊了。還有一種方法可以試試:

options.setProperty(HTTPConstants.SO_TIMEOUT, 300000);

axis2底層調用的是httpclient,它默認的嘗試連接時間是60s,建立連接后,等待接收數據的時間也是60s。上面的寫法是把等待接收數據時間延長。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM