Erste Antwort von Castle Wcf Anlage async Aufruf
-
10-10-2019 - |
Frage
sagen, ich habe einen Anruf wie folgt:
_actService.BeginWcfCall(x => x.SaveAct(new SaveActRequest
{
Act = act
}));
Wie kann ich auf die Antwort von SaveAct bekommen? Wie kann ich einen Rückruf Brand gesetzt, wenn der Vorgang abgeschlossen ist?
Ich habe versucht:
_actService.BeginWcfCall(x => x.GetAct(new GetActRequest
{
ActName =
saveScheduleSlotRequest.ScheduleSlot.ActProxy.Name
}), (result) =>
{
var async = (GetActResponse)result.AsyncState;
}, _actService);
Aber es beschwert sich über einen mehrdeutigen Aufruf?
Alle Zeiger?
Lösung
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.