1

假设我有这样的电话:

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

但它抱怨一个模棱两可的电话?

任何指针?

4

1 回答 1

0

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

我认为您可能对正常的 C# 异步模式有些困惑。它总是涉及一对 Begin/End 调用。

WCF 工具支持 2 个回调模型,由 BeginWcfCall 的最后 2 个参数确定

2 个选项是 1) Action>, state 2) AsyncCallback, state

选项 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#standard 异步模式的偏好。

于 2011-01-12T14:13:10.950 回答