我已經實現了異步模式服務:WCF異步模式不會引發故障異常
[OperationContract(AsyncPattern = true)]
IAsyncResult BeginLoadDocument(Byte[] value, AsyncCallback callback, object state);
Boolean EndLoadDocument(IAsyncResult asyncResult);
的「BeginLoadDocument」使用線程池運行在服務端的私有方法「回調」:
public IAsyncResult BeginLoadDocument(string id, AsyncCallback callback, object state)
{
PendingAsyncResult<string> asyncResult =
new PendingAsyncResult<string>(id, callback, state);
ThreadPool.QueueUserWorkItem(new WaitCallback(Callback), asyncResult);
return asyncResult;
}
回調方法加載文檔並設置「EndLoadDocument」的結果。
到目前爲止好,但我如何處理例外?
如果我在服務器端拋出exceling,我得到一個FaultedException'1
沒有處理。 我確實嘗試使用屬性[FaultContract(typeof(InforError))]
,其中「InfoError」是我的Custum DataMember,但它不起作用。
我使用SvcUtil工具構建代理/一個http:...
我的接口作爲異步簽名: [的ServiceContract] 公共接口IMyService { [OperationContract的(AsyncPattern =真)] IAsyncResult的BeginLoadDocument(字節[]值,AsyncCallback的回調,對象的狀態); Boolean EndLoadDocument(IAsyncResult asyncResult); } 我確實在客戶端使用Try-Catch,問題出現在服務器端,expect沒有處理它。如果我在服務器端使用Try-Catch,客戶端永遠不會知道異常,如果我不使用try-catch錯誤停止服務並且客戶端沒有收到任何東西。 – user429715 2010-08-24 16:18:35
兩個客戶端都知道IServiceInterface,因此他們應該知道您將寫入的ServiceFault。把它放在「常用」或任何你把IServiceInterface放在哪裏.. – ilansch 2013-03-28 06:27:48