添加 SendReply 时的工作流接收关联

Workflow Receive correlation when SendReply is added

我在工作流设计器中创建了一个简单的工作流,它有一个接收 activity 可以在工作流启动后调用。 Receive 与其中一个内容参数相关联,它是我在工作流中生成并从初始 SendReply activity.

传回的 GUID

关联查询:sm:body()/xgSc:DoSomething/xgSc:workflowId

我可以用这个测试方法执行工作流:

[TestMethod]
public void Test()
{
    using (var client = new Test.ServiceClient())
    {
        var workflowId = client.StartWorkflow();
        client.DoSomething(workflowId.Value);
    }
}

这很好用,但是当我向接收添加 SendReply activity 时,它不再正确关联,并且在调用 DoSomething 时出现此错误:

The execution of an InstancePersistenceCommand was interrupted because the instance key 'aee2a4cc-24ec-9e0e-6f76-31ffe345ae27' was not associated to an instance. This can occur because the instance or key has been cleaned up, or because the key is invalid. The key may be invalid if the message it was generated from was sent at the wrong time or contained incorrect correlation data.

这是 SendReply 的工作流程 activity:

将 SendReply activity 退出,它工作正常,所以 SendReply activity 以某种方式破坏了相关性。

如何实现与 Receive/SendReply 对的关联?

要使 SendReply activity 正常运行,必须使用 CorrelationHandle 对象设置请求-回复关联。

首先,在与 Receive 和 SendReply 活动相同(或更高)范围内的工作流中添加一个新的 CorrelationHandle 类型变量。

然后 select 接收 activity 并在属性窗格中单击 CorrelationInitializers 按钮以打开添加关联初始化程序 window。

单击 "Add initializer" 并键入 CorrelationHandle 变量的名称。

在相关类型 ComboBox select "Request-reply correlation initializer" 中单击确定关闭 window。

或者,您可以将 Recieve 和 SendReply 活动放在 CorrelationScope 中,它为其包含的消息传递活动提供隐式 CorrelationHandle。