I have a WCF service library hosted in a Windows Service. I have spent all day testing numerous scenarios with much success. However, as the application is now, I have a problem with uncaught exceptions, my FaultException<ExceptionFault>
, simply being logged by the WCF service, and then disappearing. ExceptionFault
is a simple DataContract
model that has only three string values with data describing an exception.
The WCF service uses a timer to call the following methods every 30 seconds:
public int Process(bool isForced)
{
try
{
var count = ProcessListings();
return count;
}
catch (Exception ex)
{
_logger.ErrorWithCallStack("Error while processing listings. " + ex.GetType().Name + ": " + ex.Message, ex, ex.StackTrace);
if (ex is SchedulerException)
{
throw new FaultException<ExceptionFault>(new ExceptionFault(ex), ex.Message);
}
throw;
}
}
private static int ProcessListings()
{
if (processCount % 3 == 0)
{
throw new SchedulerException("ProcessListings failed.");
}
return 0;
}
The client is a viewmodel in a WPF app. It has a command to override the timer and force Process
to execute, by calling the WCF proxy's ProcessAsync
method. When I use this, the client catches the FaultException<ExceptionFault>
and properly shows a dialogue. When the service itself executes the Process
method, one the timer's Elapsed
event, the same exception is thrown (every third time), but although this exception is not handled anywhere, the service simply ignores it and processes again the next time the timer fires.
I know exceptions in timer events are swallowed, but in this case I simply don't know what else to do. I am handling four cases of unhandled exception in the client, and if I move the timer into the windows service, and catch an unhandled exception there, where it occurs, how do I communicate it back to the WPF client?