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

Posted by Lygpt on Stack Overflow See other posts from Stack Overflow or by Lygpt
Published on 2010-03-23T15:57:25Z Indexed on 2010/03/23 16:23 UTC
Read the original article Hit count: 351

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;
}

© Stack Overflow or respective owner

Related posts about workflow-foundation-4

Related posts about workflow-foundation