我有一堆工作流基础 4.0 RC 代码活动,它们使用 Web 服务并与我想添加一些错误处理的数据库对话。
我真的希望能够尝试调用我的 Web 服务/数据库,捕获任何故障,例如通信失败,然后在 1 小时内重试相同的操作(在我记录异常之后)。
有没有办法做这样的事情?
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;
}