4

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?

Arie
  • 179
  • 2
  • 16
  • Reffer, the similiar problem: http://social.msdn.microsoft.com/Forums/vstudio/en-US/e15e8549-a6aa-48e5-99d7-37c39100a4d6/check-web-service-status?forum=csharpgeneral –  Aug 03 '14 at 13:50
  • Can you direct me to the right solution? – Arie Aug 03 '14 at 14:18
  • @Arie, can you provide a sample of code showing how you consume the service? based on your approach, the exception handling will vary. – zaitsman Aug 03 '14 at 15:28
  • Can you tell how the WCF service is hosted? since things could be quite different in self-hosted and IIS. – ZZZ Aug 03 '14 at 20:53
  • It hosted in Azure Cloud. I noticed that if I try to connect to wcf threw the wp8 app while the azure server is rebooting, it's throwing an exception. – Arie Aug 03 '14 at 21:20

3 Answers3

3

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.

usr
  • 168,620
  • 35
  • 240
  • 369
  • How can I make a low timeout? And the server is not down regulary but I want the application not to crush when it is – Arie Aug 03 '14 at 15:06
  • 1
    Are you unable to find out how to change the timeout with WCF?; If you don't want the app to crash (understandable) you should probably handle errors. You have to do that anyway. – usr Aug 03 '14 at 15:09
1

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.

evilmandarine
  • 4,241
  • 4
  • 17
  • 40
0

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.

Omer Faruk Zorlu
  • 371
  • 1
  • 18