我有同样的问题,因为this question MSDN上,但我不明白的解决方案,因为它仍然是不明确的,我如果罗马吻的解决方案将正确地更换一个端点地址,而一个单一的工作流程实例正在并发执行。解决端点绑定动态工作流
当内部Send
活动被安排由具有某个enpoint地址的一个线程执行时,该地址是否会被另一个线程覆盖,该另一个线程使用不同的端点地址调度相同的活动?纠正我,如果我错了,但我相信它会,因为Send.Endpoint
是一个普通的财产反对势必任何当前的工作流执行上下文是InArgument<Endpoint>
。
有人可以摆脱更多的光线进入呢?
UPDATE
我测试的罗马之吻提供的解决方案,而且事实证明,由于预期在我的情况下它不能正常工作。我修改Execute
方法如下:
protected override void Execute(NativeActivityContext context)
{
Thread.Sleep(Address.Get(context).EndsWith("1") ? 1000 : 0);
Body.Endpoint.Binding = GetBinding(Binding.Get(context));
Body.Endpoint.AddressUri = new Uri(Address.Get(context));
Thread.Sleep(Address.Get(context).EndsWith("1") ? 0 : 3000);
var address = Address.Get(context) + " => " + Body.Endpoint.AddressUri;
Console.WriteLine(address);
Thread.Sleep(10000);
context.ScheduleActivity(Body);
}
冉这个测试:
static void Main(string[] args)
{
// Workflow1 is just a SendScope wrapped around by a Sequence with single Address input argument exposed
var workflow = new Workflow1();
Task.WaitAll(
Task.Run(() => WorkflowInvoker.Invoke(workflow, new Dictionary<string, object> { { "Address", @"http://localhost/1" } })),
Task.Run(() => WorkflowInvoker.Invoke(workflow, new Dictionary<string, object> { { "Address", @"http://localhost/2" } })));
Console.ReadLine();
}
我得到的结果是:
http://localhost/1 => http://localhost/1
http://localhost/2 => http://localhost/1
问题仍然是开放的:我怎么在运行时分配我Send
活动的端点地址动态?
我正在执行一个Workflow的实例,如下所示: 'Activity workflow1 = new Workflow1(); Task.WaitAll( Task.Run(()=> WorkflowInvoker.Invoke(workflow1)), Task.Run(()=> WorkflowInvoker.Invoke(workflow1)));' 尽管在'CacheMetadata'断点只击中一次。 – yuramag