从 Castle Wcf 设施异步调用获取响应

发布于 2024-10-11 07:20:00 字数 1105 浏览 8 评论 0原文

假设我有一个这样的电话:

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

但它抱怨一个不明确的调用?

有什么指点吗?

Say I have a call like so:

 _actService.BeginWcfCall(x => x.SaveAct(new SaveActRequest
                                                             {
                                                                 Act = act
                                                             }));

How do I get to the response of SaveAct? How can I set up a callback to fire when the operation completes?

I have tried:

    _actService.BeginWcfCall(x => x.GetAct(new GetActRequest
                                                            {
                                                                ActName =
                                                                    saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name
                                                            }), (result) =>
                                                                    {
                                                                        var async = (GetActResponse)result.AsyncState;

                                                                    }, _actService);

But it complains about an ambiguous call?

Any pointers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-10-18 07:20:00

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

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

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

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

Craig Neuwirt answered this: http://groups.google.com/group/castle-project-users/browse_thread/thread/f440dbd05e60484f

I think you may be a little confused about the normal C# async pattern.
It always involve a pair of Begin/End calls.

The WCF Facility support 2 callback models which is determined by the last 2 arguments of your BeginWcfCall

The 2 options are
1) Action>, state
2) AsyncCallback, state

Option 1 is the standard async pattern and would look like this

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

As you can see, the first requires a reference to the _actService proxy to call end. The first is a convenience method which does not.

 _actService.BeginWcfCall(x => x.GetAct(new GetActRequest 
                                                            { 
                                                                ActName = 
                                                                    saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name 
                                                            }), (IWcfAsyncCall<GetActResponse> result) => 
                                                                    { 
                                                                        var response =  result.End(); 
                                                                        // Do something with the response 
                                                                    }); 

The choice of which approach depends entirely on your preference of the c#standard async pattern.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文