Hi
I wanted to share once again one little piece of information that i bumped into while developing a software for my Windows Phone.
I was trying to figure out how to test whether a web service was online so i created a simple "isAlive" method that returns a Boolean. Of course if the web service is offline the method will not respond. Actually the whole end point will throw an exception.
There was no useful info on the web so with trial and error i noticed this behavior.
I made a user control with Visual Studio & Expression Blend which indicates whether the service is online or not:
The code itself is quite straight forward. But the thing that did not cross my mind at this point was that the request is asynchronous which means that there is no place for a try catch except the proxy class (reference.cs) of the Web Service. Obviously I do not want to touch that class since it is auto-generated.
So what happens if the service is not alive?
The service proxy class will throw an EndpointNotFoundException. This is the one that you are unable to catch and go around. But guess what.. This happens only in the emulator and you can actually continue debugging by hitting F5.
So here’s what you can do about it:
Check the e.Error from isAliveCompletedEventArgs and if that is null you did not hit an exception and vice versa.
The phone itself does not throw the exception visible at all so with this approach you can handle the situation. Different story is should you test for overall data connectivity before making the first call.
Happy coding!