web service throws uncatchable exception

Jan 3 2006 5:54 PM
I am testing what will happen when I call my web service when IIS is stopped. My expectation is that an excpetion would be thrown. I would like to catch that exception and do some handling.
In actuality, what happens is that an exception is thrown (System.Net.WebException {"Unable to connect to the remote server"} {"No connection could be made because the target machine actively refused it"}) as expected, but I cannnot catch the exception.
The call to the web service is in a try block with two catch blocks, one for System.Net.WebException and one for Exception, I have breakpoints in both catch blocks, and neither gets hit. Instead what happens is that a dialog box pops up when the call to the web service is executed. I am running in debug mode, using visual studio 2005. The code works fine when IIS is running.
I have successfully caught System.Net.WebException using this same code under different circumstances, but I can't cath it when it is caused by IIS being stopped.
I have repeated the behavior using the default Hello World web service that is created when you create a new web service in VS 2005. With this Web service, the exception also throws up a dialog and refuses to be caught, despite the presence of cath blocks. The only difference is that with the helloworld web service, the exception is thrown on the "new" command, whereas with my web service, the exception is not thrown until I call one of the functions of the service.
Just to clarify, the Hello World web service must be deployed in IIS for you to be able to repeat this. I have tested that the call to the Hello World web service works fine when IIS is running - the problem occurs when IIS is stopped - of course, the problem is not that an exception is being thrown - I expect that - the problem is that I can't catch it.
Any help would be appreciated.
Also, in case I can't solve this, I am looking for a workaround where I could call IIS directly (through some API?) to determine whether it is running before I make the call to my web service. Does anyone know how to do this?
This is the code in which I am calling Hello World web service:
try
{
HelloWorldWS.Service ws = new HelloWorldWS.Service(); //exception thrown on this line
string str = ws.HelloWorld();
System.Console.WriteLine(str);
}
catch (System.Net.WebException ex)
{
System.Console.WriteLine(ex.Message); //never gets here
}
catch (Exception e)
{
System.Console.WriteLine(e.Message); //never gets here
}

This is the code in which I am calling my web service

//new has already been called on m_DecoderWS with no exception thrown (even though IIS is stopped)

try
{
this.m_DecoderWS.Ping(); //exception thrown on this line
}
catch (System.Net.WebException ex)
{
//some code here, but never gets here
}
catch (Exception e)
{
//some code here, but never gets here
}


Thanks!