【webservice】Axis2 客户端调用 设置超时时间

来源:互联网 发布:网站推广优化 编辑:程序博客网 时间:2024/05/23 01:14

转载自  http://www.cnblogs.com/dingmy/p/3712204.html


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。上面的写法是把等待接收数据时间延长。

0 0