Castle WCF Async callback

132 views
Skip to first unread message

Wayne Douglas

unread,
Jan 10, 2011, 3:23:37 PM1/10/11
to castle-pro...@googlegroups.com
Hi 

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?


--
Cheers,

w://

Craig Neuwirt

unread,
Jan 10, 2011, 3:48:17 PM1/10/11
to castle-pro...@googlegroups.com
You should just be able to treat it like normal async pattern and pass callback and state object as 2 and 3 args




On Jan 10, 2011, at 2:23 PM, Wayne Douglas wrote:

Hi 

Say I have a call like so:

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

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


--
Cheers,

w://

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Krzysztof Koźmic

unread,
Jan 10, 2011, 4:24:52 PM1/10/11
to castle-pro...@googlegroups.com

Wayne Douglas

unread,
Jan 12, 2011, 3:34:04 AM1/12/11
to castle-pro...@googlegroups.com
i'm probably being dumb here, but how do i get to the result of this call?

_actService.BeginWcfCall(x => x.GetAct(new GetActRequest
                                                            {
                                                                ActName =
                                                                    saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name
                                                            }));

i've tried passing in an anonymous method as the callback:

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

but something isn't right...

2011/1/10 Krzysztof Koźmic <krzyszto...@gmail.com>



--
Cheers,

w://

Wayne Douglas

unread,
Jan 12, 2011, 3:42:45 AM1/12/11
to castle-pro...@googlegroups.com
this also doesn't work:

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


complains about an ambiguous call?

2011/1/12 Wayne Douglas <codin...@googlemail.com>



--
Cheers,

w://

Craig Neuwirt

unread,
Jan 12, 2011, 8:17:21 AM1/12/11
to castle-pro...@googlegroups.com
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<IWcfAsyncCall<TResult>>, 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.

-craig

Wayne Douglas

unread,
Jan 12, 2011, 8:54:02 AM1/12/11
to castle-pro...@googlegroups.com
thanks for that

i def was getting it all mixed up - the only other time ive done async services is on the iPhone using monotouch :)

Craig Neuwirt

unread,
Jan 12, 2011, 9:29:48 AM1/12/11
to castle-pro...@googlegroups.com
No problem.  C# has too many ways to do async nowadays and it can definitely be confusing

Wayne Douglas

unread,
Jan 12, 2011, 9:37:28 AM1/12/11
to castle-pro...@googlegroups.com
i answered this: 


if you want to add your own i'll mark it as correct [if you care about such things] :) 

On Wed, Jan 12, 2011 at 2:29 PM, Craig Neuwirt <cneu...@gmail.com> wrote:
oo many ways to do async nowaday



--
Cheers,

w://

Krzysztof Koźmic

unread,
Jan 12, 2011, 5:28:49 PM1/12/11
to castle-pro...@googlegroups.com
Guys - feel more than welcome to update the doco to avoid more people being confused about that.

In general WCF Facility has a very poor doco, and actually yesterday one friend asked me if it was abandoned already.

cheers,

Dry and safe Krzysztof
Reply all
Reply to author
Forward
0 new messages