Getting response from Castle Wcf facility async call
Say I have a call like so:
_actService.BeginWcfCall(x => x.SaveAct(new SaveActRequest开发者_Python百科
{
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?
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.
精彩评论