In my WCF client class I'm handling the Faulted()
event so that if the remote service throws an exception and faults the channel I can still at least shut it down gracefully. Here's my code:
protected void RemoteDataRetriever_Faulted(object sender, EventArgs e)
{
(sender as ICommunicationObject).Abort();
this.Dispose();
throw new ChannelTerminatedException("The remote service threw an unhandled exception and as a result the channel has been closed.");
}
So what I would expect is that the client can handle the ChannelTerminatedException
that I've thrown manually and send a message to the user, etc. Instead my exception is getting wrapped in a System.ServiceModel.Diagnostics.CallbackException
. Ok, fine. Except here's the catch: this CallbackException doesn't exist in the ServiceModel library and there appears to be no way for me to handle it except as a generic Exception
, which does me no good for my unit tests. What the heck is going on here? Can I disable that somehow and throw the exception that I originally wanted?