2014-01-13 49 views
1

我有一個關於WCF故障異常的問題。我正在實現IErrorHandler接口並創建FaultExceptionWcf錯誤處理使用IErrorHandler接口

我的問題是這樣的:當我在創建FaultException,是沒有辦法,我必須遵循發送友好的錯誤信息給客戶端的模式?

我使用HandleError方法將實際異常記錄到數據庫,並在ProvideFault方法中創建FaultException

鑑於delow,我有IErrorHandler接口的示例實現。

public bool HandleError(Exception error) 
{ 
    System.Diagnostics.Debug.WriteLine(error.Message); 
      // Log the error to the Db 
    return true; 
} 

public void ProvideFault(Exception error, MessageVersion version, ref Message fault) 
{ 
     // Here is a sample that I was playing with. 
    MessageFault faultException; 
    if(error is DataException) 
     faultException = new FaultException<string>(ErrorStrings.DatabaseOpenError, new FaultReason(ErrorStrings.DatabaseOpenError)).CreateMessageFault(); 
    else if (error is NullReferenceException) 
     faultException = new FaultException<string>(ErrorStrings.NullDataError, new FaultReason(ErrorStrings.NullDataError)).CreateMessageFault(); 
    else 
     faultException = new FaultException<string>(ErrorStrings.GeneralError, new FaultReason(ErrorStrings.GeneralError)).CreateMessageFault(); 

    fault = Message.CreateMessage(version, faultException, ""); 
} 

我需要確切瞭解裏面ProvideFault方法做一個友好故障返回給用戶一些清晰度。我也計劃使用本地化來顯示錯誤。不知道這是由客戶端完成,還是服務應該發送本地化的消息。

根據我閱讀,我不應該從錯誤或錯誤的EntityFramework由於安全原因,發送堆棧的信息,如EntityValidation錯誤等問題,給客戶端。

在這種情況下,我需要檢查異常和礦細節的類型發送到客戶端之前更合適?

回答