WF4:活动关联Activity|WF4:活动关联Activity correlation
Activity correlation:活动关联,确保两个活动一起工作。
当使用多个活动来完成单个操作时需要使用Activity correlation,WF4中的Send和ReceiveReply活动就是很好的例子。当我们使用ReceiveAndSendReply 或 SendAndReceiveReply 模板时,需要的活动的关联都已经自动的配置好了,但是如果我们在代码中使用Send 和 ReceiveReply或者 Receive 和SendReply活动时,就需要自己手动去实现,如没有改关联会有下面异常:System.InvalidOperationException:
The Send activity is configured with a request/reply Operation 'GetData', however, there is no ReceiveReply activity paired with it. Please pair Send with ReceiveReply and correlate them using a CorrelationHandle.
有不同的方式来配置活动关联,第一种就是使用CorrelationScope活动,CorrelationScope会自动的创建所需要的关联句柄,并且消息活动将会使用这个句柄。
下面是例子:
static Activity CreateWorkflow()
{
var getDataResult = new Variable();
var handel = new Variable();
var send = new Send()
{
CorrelationInitializers =
{
new RequestReplyCorrelationInitializer()
{
CorrelationHandle = handel
}
},
OperationName = "GetData",
ServiceContractName = "IService1",
Endpoint = new Endpoint()
{
Binding = new BasicHttpBinding(),
AddressUri = new Uri("http://localhost:8080/GetDataService/")
},
Content = new SendParametersContent()
{
Parameters =
{
{"value", new InArgument(42)}
}
}
};
var receive = new ReceiveReply()
{
Request = send,
Content = new ReceiveParametersContent
{
Parameters =
{
{"GetDataResult", new OutArgument(getDataResult)}
}
}
};
var workflow = new Sequence()
{
Variables = { getDataResult, handel },
Activities =
{
send,
receive,
new WriteLine() { Text = getDataResult }
}
};
return workflow;
}
【WF4:活动关联Activity|WF4:活动关联Activity correlation】上面我们是使用RequestReplyCorrelationInitializer,我们还可以使用CorrelationScope来完成同样的事情,创建同样的工作流,如下:
static Activity CreateWorkflow()
{
var getDataResult = new Variable();
var send = new Send()
{
OperationName = "GetData",
ServiceContractName = "IService1",
Endpoint = new Endpoint()
{
Binding = new BasicHttpBinding(),
AddressUri = new Uri("http://localhost:8080/GetDataService/")
},
Content = new SendParametersContent()
{
Parameters =
{
{"value", new InArgument(42)}
}
}
};
var receive = new ReceiveReply()
{
Request = send,
Content = new ReceiveParametersContent
{
Parameters =
{
{"GetDataResult", new OutArgument(getDataResult)}
}
}
};
var workflow = new Sequence()
{
Variables = { getDataResult },
Activities =
{
new CorrelationScope()
{
Body = new Sequence()
{
Activities = { send, receive }
}
},
new WriteLine() { Text = getDataResult } }
};
return workflow;
}本文转自生鱼片博客园博客,原文链接:http://www.cnblogs.com/carysun/archive/2009/12/06/wf4-Activitycorrelation.html,如需转载请自行联系原作者
推荐阅读
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- 以读攻“毒”唤新活动曹彦斌打卡第二天
- 20170801
- 敬老院活动
- 积极探索|积极探索 绽放生命 ???——心心相印计划:青少年心理工作研讨小组全国大型公益行动第二次活动包头市青山区分校圆满成功
- 我校积极开展结核病防治宣传活动
- 湖州大学生实践团开展系列活动践行生态文明理念
- 以史之名,缅怀先烈;以烛之光,予之以暖。——淮北师范大学南京大屠杀死难者国家公祭日纪念活动
- 2019年的第一次洋葱线下读书会活动
- 让未来现在就来