在 StateMachine 中使用 CallExternalMethodActivity/HandleExternalEventActivity
我试图让 StateMachine 在状态之间执行一些数据库操作。
因此,我有一个“启动”状态,它使用 CallExternalMethodActivity 在用ExternalDataExchangeAttribute 装饰的类上调用“BeginExecuteNonQuery”函数。之后,它使用 SetStateActivity 更改为“结束”状态。
“结束”状态使用 HandleExternalEventActivity 来侦听“EndExecuteNonQuery”事件。
我可以单步执行本地服务,进入“BeginExecuteNonQuery”函数。
问题是“EndExecuteNonQuery”为空。
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);
}
我的实施做错了什么?
-斯坦
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法从代码片段中看出,但请确保您使用ExternalDataExchangeService 来托管您的服务,并且不要将您的服务直接添加到运行时。 ExternalDataExchangeService 负责添加所需的事件处理程序并将事件转换为工作流的排队消息。
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.
我通过更改配置文件来使用没有代码的ExternalDataExchangeService,如下所示 此处:
I'm using ExternalDataExchangeService without code by changing my config file as shown here :