Enteprise Library Exception Handling for WCF Fault Contracts - CLIENT SIDE
Posted
by Huw
on Stack Overflow
See other posts from Stack Overflow
or by Huw
Published on 2010-05-13T14:59:46Z
Indexed on
2010/05/13
16:14 UTC
Read the original article
Hit count: 553
I have a Windows Service which communicates with WCF services. The WCF services are all fault shielded and generate custom UserFaultContracts and ServiceFaultContracts. No problems there.
In the Windows Service I am using EntLib for exception handling and logging.
I do not want to try catch for faults
try
{
}
catch (FaultException<UserFaultContract>)
{
}
I want to use EntLib
try
{
}
catch (Exception ex)
{
var rethrow = ExceptionPolicy.HandleException(ex, "Transaction Policy");
if (rethrow) throw;
}
This also works, however, in my Tranasaction Policy I want to Log the details of the UserFaultContract. This is where I am unglued. And I hate becoming unglued. The fault is captured and logged...but I can't get the details of the fault.
My exception policy is
<add name="Transaction Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="None" name="Exception">
<exceptionHandlers>
<add logCategory="General" eventId="200" severity="Error" title="Transaction Error"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
priority="2" useDefaultLogger="true" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Logging Handler" />
</exceptionHandlers>
</add>
<add type="System.ServiceModel.FaultException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="None" name="FaultException">
<exceptionHandlers>
<add logCategory="General" eventId="200" severity="Error" title="Service Fault"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
priority="2" useDefaultLogger="true" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
The exception logged is:
Timestamp: 5/13/2010 14:53:40 Message: HandlingInstanceID: e9038634-e16e-4d87-ab1e-92379431838b
An exception of type 'System.ServiceModel.FaultException`1[[LCI.DispatchMaster.FaultContracts.ServiceFaultContract, LCI.DispatchMaster.FaultContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' occurred and was caught.
05/13/2010 10:53:40 Type : System.ServiceModel.FaultException`1[[LCI.DispatchMaster.FaultContracts.ServiceFaultContract, LCI.DispatchMaster.FaultContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : There was an internal fault at the DispatchMaster service. Source : mscorlib Help link : Detail : LCI.DispatchMaster.FaultContracts.ServiceFaultContract Action : http://LCI.DispatchMaster.LogicalChoices.com/ITruckMasterService/MergeScenarioServiceFaultContractFault Code : System.ServiceModel.FaultCode Reason : There was an internal fault at the DispatchMaster service. Data : System.Collections.ListDictionaryInternal TargetSite : Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage) Stack Trace :
In the fault contact there is an ID and a Message. I would, as you can see, like the ID and Message to be logged by EntLib.
I am assuming that I'm going to have to write a custom handler to exctract the fault details - but thought I'd ask if I'm missing something in EntLib which might help me avoid that task.
Thanks to anyone who is willing to help.
© Stack Overflow or respective owner