I'm calling a web service from within a Silverlight Windows phone 7 application which works fine if the web service is available. If the web service is unavailable then an unhandled exception is caught but I don't seem able to catch it myself. My attempt is as follows:
//Get list of providers from Webservice
RSAServiceClient proxy = new RSAServiceClient();
proxy.GetSuppliersCompleted += new System.EventHandler<GetSuppliersCompletedEventArgs>(ProxyGetSuppliersCompleted);
try
{
proxy.GetSuppliersAsync();
}
catch (EndpointNotFoundException)
{
//TODO: Handle webserice not being available
}
catch (Exception)
{
throw;
}
But this doesn't catch the exception and obviously GetSuppliersCompleted never get's called so I can't catch it there.
I then thought I may be able to detect it by checking the connection state (proxy.State) but this despite the web service not running returns CommunicationState.Opened.
Any idea's where I can handle this?
Apologies if I've missed something but I have searched and not found a solution.
You should place your catch in your ProxyGetSuppliersCompleted
method.
An attempt to access the result will throw the error you are expecting.
Alternatively in the ProxyGetSuppliersCompleted
you can test the Error
property of the EventArgs which will contain the exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With