我的要求是,兩個不同類型的警報消息的需要指定 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