2012-01-25 4 views
2

AppDomain.CurrentDomain.UnhandledException을 사용하여 예외를 기록하려고합니다. wcf 서비스 콜백에서 예외를 처리하는 방법

AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; 
public static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) 
{ 
     HandleException(e.ExceptionObject as Exception); 
} 

내가 디버그 시간에 클라이언트에 오류를 얻을 것이다하지만 AppDomain.CurrentDomain.UnhandledException에 푹 이벤트가 발생되지 않습니다 서버에서 예외가

.

는 서버 :

[ServiceBehavior(IncludeExceptionDetailInFaults=true)] 
public class Service : IService 
{   

    public string GetError() 
    { 
     throw new ApplicationException(); 
    } 
} 

클라이언트 :

public void GetError() 
{ 
    this.service.BeginGetError(OnGetErrorCompleted, null); 
} 

public void OnGetErrorCompleted(IAsyncResult result) 
{ 
    var value = this.service.EndGetError(result); 
} 

내가 Distpacher.BeginInvoke를 사용하지 않는 한이 작동하지 않습니다 ..

public void OnGetErrorCompleted(IAsyncResult result) 
{ 
    this.Dispatcher.BeginInvoke((Action)(() => 
    { 
     var value = this.service.EndGetError(result); 
    }));   
} 

누군가가 이유를 알고있다? 나는 모든 스레드에서 예외 발생시 AppDomain.CurrentDomain.UnhandledException이 발생한다고 생각했습니다! : S

답변

0

보다 나은 해결책은 IErrorHandler과 같은 것을 사용하고 FaultExceptions를 던집니다. FaultContract 속성을 사용하여 FaultExceptions을 던지도록 작업을 꾸미십시오. 이제 클라이언트에서 특정 FaultExceptions를 포착 할 수 있습니다. 서버의 예외를 클라이언트에 노출 시켜서는 안됩니다.

+0

나는 이미 [ServiceBehavior (IncludeExceptionDetailInFaults = true)]를 사용하여 서버의 오류를 예외로 변환하고 있습니다. 또한 Entreprise 라이브러리 예외를 사용하여 오류 변환 및 FaultContracts 사용을 시도했습니다. 그래서 나는 클라이언트에 대한 예외를 얻지 않을 것이지만 잘못은 아닙니다. –

+0

여전히 서버 예외가 클라이언트에 노출되어 있습니다. 클라이언트가 서버에서 발생한 일을 어떻게 처리해야합니까? 'IncludeExceptionDetailInFaults'를 사용하지 말고'IErrorHandler'와 같은 것을 사용하여 오류를 제공하십시오. – diggingforfire

관련 문제