我的要求是,两个不同类型的警报消息的需要指定 Android应用程序正在访问wcf
服务,如何识别WCF服务工作或没有使用Android
- 如果
WCF
服务无法正常工作。我要告诉消息"Service is not working"
- 服务工作正常,但访问时间长则需要告诉
"Timeout to connect to service."
第二个选项我已经做了。我们如何才能找到服务正在工作与否?有可能检查吗?
我的要求是,两个不同类型的警报消息的需要指定 Android应用程序正在访问wcf
服务,如何识别WCF服务工作或没有使用Android
WCF
服务无法正常工作。我要告诉消息"Service is not working"
"Timeout to connect to service."
第二个选项我已经做了。我们如何才能找到服务正在工作与否?有可能检查吗?
1. if WCF service is not working, . I have to tell the message "Service is not working "
确保您的HTTP请求的类检查的404错误代码,如果错误代码是404,那么你可以告诉用户该服务已关闭。
2. Service is working fine, but accessing time is long then need to tell "Timeout to connect to service."
您可以通过两种方式做到这一点,首先,有一个TimerTask或延迟处理所需超时后运行,当然后取消请求,并显示超时错误。另一种更好的方法是使用setConnectionTimeout
()和setSoTimeout()
来设置请求本身的超时值,ontimeout会产生一个ConnectTimeoutException
,您可以捕获它以显示该消息。
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 60000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient client = new DefaultHttpClient(httpParameters);
谢谢你的回答。第二个选项确定。在第一个选项中,我们如何获取错误代码?我正在使用Ksoap。 SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);数据转化为肥皂 envelope.dotNet = true; envelope.setOutputSoapObject(request); AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL); try { httpTransport.call(SOAP_ACTION,envelope); responses =(SoapPrimitive)envelope.getResponse(); } catch(Exception e){} – Piraba