开发者

Workflow 4.0 code activities calling other activites (persist, delay etc)

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 开发者_如何学JAVAactivity 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;
}


Yes that is not difficult at all once you know how WF4 activities work.

I could type a long story but as Richard Blewett has already blogged about a Retry activity that does the exact retry action you describe I am just going to link to that blog post here. The only thing missing is the persist but that should be easy to add.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜