说我有这样的电话:

 _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);

但是它抱怨电话模棱两可吗?

有指针吗?

有帮助吗?

解决方案

Craig Neuwirt回答了这一点: http://groups.google.com/group/castle-project-users/browse_thread/thread/thread/f440dbd05e60484f

我认为您可能对普通C#异步模式有些困惑。它总是涉及一对开始/结束通话。

WCF设施支持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代理以致电端。第一个是一种便利方法,没有。

 _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#标准异步模式的偏好。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top