2011-01-12 72 views
1

說我有像這樣的電話:從城堡WCF設施異步調用獲得響應

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

但它抱怨一個模棱兩可的電話嗎?

任何指針?

+0

你必須明確指定`result`的類型我認爲 – 2011-01-12 12:29:11

回答

0

克雷格Neuwirt的回答是:http://groups.google.com/group/castle-project-users/browse_thread/thread/f440dbd05e60484f

我想你可能會有點困惑正常的C#異步模式。 它始終涉及一對開始/結束調用。

這是由過去的2個參數的您BeginWcfCall

的2個選項是 1)動作>,狀態 2)的AsyncCallback,狀態

選項1是確定的WCF基金支持2回調模型標準異步模式,看起來像這樣

 _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#標準異步模式的偏好。