views:

300

answers:

2

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

+1  A: 

I can't tell from the code snippet but make sure you are using the ExternalDataExchangeService to host your service and don't add you service directly to the runtime. The ExternalDataExchangeService is responsible for adding the required eventhandlers and turning the events into queued messages for the workflow.

Maurice
I am using the ExternalDataExchangeService...I will post more code for you to see...
AngrySpade
And you are right... I am not using the ExternalDataExchangeService...Let me try and see how it goes...
AngrySpade
Yup...You were right..
AngrySpade
A: 

I'm using ExternalDataExchangeService without code by changing my config file as shown here :

controlbreak