I'm making a WP8 application. I noticed that if the server is working everything works good, but if the server is down I get an exception.
How can I check in the code if the wcf service is activated before using his methods?
I'm making a WP8 application. I noticed that if the server is working everything works good, but if the server is down I get an exception.
How can I check in the code if the wcf service is activated before using his methods?
Implement a no-op method in your web-service and call it with a low timeout. If it works, the service is up. If the call fails for whatever reason, the service is down.
Actually, why is the server even down regularly? Maybe it is easier to ensure that it is available at all times.
if you want to check if the server is up, you may use the Ping() class, in which you can easily define a timeout based on the network configuration, to assume server is running or not.
If you would like to check if the service is running on the server, you can define a method like this server side:
public bool IsRunning() { return true; }
and use a try-catch block client-side handling FaultException
. When calling this method, it will either return true or an exception will be thrown if service is down. You may also want to check if your client WCF proxy is not in Faulted state before calling its methods.
There is no way to learn this. It is a realy exceptional case. If you ensure the server is not down, easily to ping this or try download a simple static file like a text/html file soon as size of smaller one. supafly's answer is not wrong but it is same case as were you are.