说我有这样的电话:
_actService.BeginWcfCall(x => x.SaveAct(new SaveActRequest
{
Act = act
}));
如何获得SaveAct的回复?如何在操作完成时设置要触发的回调?
我试过了:
_actService.BeginWcfCall(x => x.GetAct(new GetActRequest
{
ActName =
saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name
}), (result) =>
{
var async = (GetActResponse)result.AsyncState;
}, _actService);
但它抱怨一个模棱两可的电话?
任何指针?
答案 0 :(得分:0)
Craig Neuwirt回答了这个问题:http://groups.google.com/group/castle-project-users/browse_thread/thread/f440dbd05e60484f
我认为你可能对正常的C#异步模式有点困惑。 它总是涉及一对开始/结束通话。
WCF Facility支持2个回调模型,这些模型由您的BeginWcfCall的最后两个参数决定
这两个选项是 1)动作>,状态 2)AsyncCallback,状态
选项1是标准的异步模式,看起来像这样
_actService.BeginWcfCall(x => x.GetAct(new GetActRequest
{
ActName =
saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name
}), (IAsyncResult result) =>
{
var response = _actService.EndWcfCall<GetActResponse>(result);
// Do something with the response
});
如您所见,第一个需要引用_actService代理来调用end。第一种是便利方法,而不是。
_actService.BeginWcfCall(x => x.GetAct(new GetActRequest
{
ActName =
saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name
}), (IWcfAsyncCall<GetActResponse> result) =>
{
var response = result.End();
// Do something with the response
});
选择哪种方法完全取决于您对c#标准异步模式的偏好。