I have a bunch of Workflow foundation 4.0 RC code activities that consume web services and talk to databases that I want to add some error handling in.
I would really like to be able to attempt to call my web service / db, catch any faults such as a communication failure and then retry the same operation in 1 hours time (after I have logged the exception).
Is there a way of doing something like this?
protected override void Execute(CodeActivityContext context) {
Persist(); // I would like to invoke the persist activity like this
if (!AttemptServiceCall()) {
// I would like to invoke a delay activity like this
Delay(new TimeSpan(0, 30, 0)); // wait 30 mins before trying again
Execute(context); // call this activity again
}
}
private bool AttemptServiceCall() {
bool serviceCallSuccessful = true;
try {
myService.InvokeSomeMethod();
}
catch (CommunicationException ex) {
myEventLogger.Log(ex);
serviceCallSuccessful = false;
}
return serviceCallSuccessful;
}