Using CallExternalMethodActivity/HandleExternalEventActivity in StateMachine

Posted by AngrySpade on Stack Overflow See other posts from Stack Overflow or by AngrySpade
Published on 2009-08-27T19:53:11Z Indexed on 2010/03/19 14:11 UTC
Read the original article Hit count: 363

I'm attempting to make a StateMachine execute some database action between states.

So I have a "starting" state that uses CallExternalMethodActivity to call a "BeginExecuteNonQuery" function on an class decorated with ExternalDataExchangeAttribute. After that it uses a SetStateActivity to change to an "ending" state.

The "ending" state uses a HandleExternalEventActivity to listen to a "EndExecuteNonQuery" event.

I can step through the local service, into the "BeginExecuteNonQuery" function.

The problem is that the "EndExecuteNonQuery" is null.

public class FailoverWorkflowController : IFailoverWorkflowController
{
    private readonly WorkflowRuntime workflowRuntime;

    private readonly FailoverWorkflowControlService failoverWorkflowControlService;
    private readonly DatabaseControlService databaseControlService;

    public FailoverWorkflowController()
    {
    	workflowRuntime = new WorkflowRuntime();
    	workflowRuntime.WorkflowCompleted += workflowRuntime_WorkflowCompleted;
    	workflowRuntime.WorkflowTerminated += workflowRuntime_WorkflowTerminated;

    	ExternalDataExchangeService dataExchangeService = new ExternalDataExchangeService();
    	workflowRuntime.AddService(dataExchangeService);

    	databaseControlService = new DatabaseControlService();
    	workflowRuntime.AddService(databaseControlService);

    	workflowRuntime.StartRuntime();
    }

    ...
}

...

public void BeginExecuteNonQuery(string command)
{
    Guid workflowInstanceID = WorkflowEnvironment.WorkflowInstanceId;

    ThreadPool.QueueUserWorkItem(delegate(object state)
    								 {
    									 try
    									 {
    										 int result = ExecuteNonQuery((string)state);
    										 EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, result));
    									 }
    									 catch (Exception exception)
    									 {
    										 EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, exception));
    									 }
    								 }, command);
}

What am I doing wrong with my implementation?

-Stan

© Stack Overflow or respective owner

Related posts about workflow-foundation

Related posts about c#