问题描述
- 通过myeclipse生成的webservice代码,访问超时
-
目前遇到一个问题,通过Myeclipse生成的webservice客户端代码(好像是jax-ws),如果访问的url不存在,就一直卡着,很久才报超时异常,有没有什么办法可以设置超时时间public ServiceCD() { super( CD_WSDL_LOCATION, new QName( "http://xx.com/basic/atomic/operation.CD", "CD")); }
上面是生成的代码。以下是我访问的代码:访问的时候就一直卡在这里。
网上有很多方法都不起作用。我使用过的方法有:ServiceCD service = new ServiceCD(url, new QName( url, "CD")); 1、Map<String, Object> ctxt = ((BindingProvider)port).getRequestContext(); ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, config.getConntimeout()); ctxt.put(BindingProviderProperties.REQUEST_TIMEOUT, config.getTimeout()); 2、URL mbr_service_url = new URL(null,GlobalVars.MemberService_WSDL, new URLStreamHandler() { @Override protected URLConnection openConnection(URL url) throws IOException { URL clone_url = new URL(url.toString()); HttpURLConnection clone_urlconnection = (HttpURLConnection) clone_url.openConnection(); // TimeOut settings clone_urlconnection.setConnectTimeout(10000); clone_urlconnection.setReadTimeout(10000); return (clone_urlconnection); } }); ServiceCD service = new ServiceCD(mbr_service_url); ``` 这些都不起作用。 求助!!!!
解决方案
HttpURLConnection conn = null;
OutputStream out = null;
String rsp = null;
try {
try {
conn = getConnection(new URL(url), METHOD_POST, ctype, headerMap);
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);
你要对connection设置超时时间,
时间: 2024-12-02 07:45:13