Including HandlingInstanceID in WCF Fault Contract

Topics: Exception Handling Application Block, Logging Application Block
Jul 28, 2010 at 3:23 PM
Using Enterprise Library 5.0, I'm attempting to Log and shield an exception while keeping the GUID between the logged error and the FaultID in the WCF FaultContract the same. For Now, I'm logging to the event log. My configuration is setup to capture the exception type of All Exceptions, then handle it with a Logging handler and a Fault Contract Exception Hanlder. The post handling action on the exception type is Throw New Exception. What happens (to the best of my knowledge), is that the exception is thrown, the policy handles the exception by logging it (in this case a System.Data.EntityException) with the GUID and creating a FaultContract of my specified type. The message and handlinginstanceID fields are mapped to appropriate properties. Since the handler is throwing a new exception, the new exception (this time a type of WCF fault wrapper) is thrown and the policy is executed a second time, logging my fault wrapper (with a different guid since it's a different error) and returning the fault response to the client. The guid returned is the 2nd one created and does not match the original logged error which has all of the detail. I would like them to match! I have tried several different strategies in the configuration, the code, and the "Assisting Support Staff" section of the 5.0 documentation. All the examples I can find do not use the WCF fault contract. I simply want to log an error (with the full detail) then return a shielded message to the client and have the Guids match between the log and the response - is that so much to ask? ;-) Any help in this area (after several hours of tinkering) would be greatly appreciated! Thank you!
Jul 29, 2010 at 12:06 PM

Hi,

I'm a little bit confused regarding your problem. Is my understanding correct that the one that doesn't match is the handlingInstanceID between the Logged exception and the exception returned to the client? Or is it between the first execution of your operation contract and the second execution?

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 29, 2010 at 1:04 PM
Correct, in a single execution of the method (which generates the error) I get 2 logs (one of a type System.Data.EntityException and the second one is the fault contract wrapper). The 2 logs have different Guids. The response returned to the client has the guid of the 2nd log. I want to return the guid of the first log since it's the one with the relevant detail.
Aug 3, 2010 at 2:58 AM

Hmm I tried to reproduce your problem, configured an Exception Policy, added 2 exception handler specifically a Log Exception Handler and a Fault Contract Handler but I was able to got the same handlingInstanceID from the EventLog logged by Log Handler and the Fault Contract Handler (response returned to the client). So I'm really not sure how have you been able to encounter this. Given this could you post your configuration here or maybe if you have a sample app that can reproduce this could you send it to us (entlib.support@avanade.com). 

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com