2

我有一堆工作流基础 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;
}
4

1 回答 1

2

是的,一旦您了解了 WF4 活动的工作原理,这一点都不难。

我可以输入一个长篇故事,但由于 Richard Blewett 已经在博客中介绍了一个 Retry 活动,该活动执行您描述的确切重试操作,我将在此处链接到该博客文章。唯一缺少的是持久化,但这应该很容易添加。

Just create your AttemptServiceCall activity and add it as the body. Given that it sounds like a potentially long running action I would suggest using an AsyncCodeActivity as the base class.

于 2010-03-23T16:21:20.747 回答