WCF ExceptionShielding Error ID does not match up with handlingInstanceId passed to Handler

.NetWcfExceptionEnterprise LibraryFault

.Net Problem Overview


I have the following decorated on my service

<ExceptionShielding("MyExceptionPolicyName")>

when a fault exception is thrown, my policy picks up the error and logs in just fine. It takes the handlingInstance Id and logs it along with the error for reference. What I'm noticing, is the Guid returned in the Fault "Error ID:" is different than that one passed into the handling instanceId.

I've also tried to decorate the operation like so

<FaultContract(GetType(ValidationFault))>

but this produces the same results.

What I would like to do is some how capture that "Error ID:" passed back to the consumer so I can log it along with the exception. *addition info: the exception policy handler is a custom one that takes an exception, and logs it's various properties and data into a specific exception log db schema.

Anyone know how to accomplish this?

UPDATE: per @Jay Patel 's comment, I added this to my config to enable tracing

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "c:\Temp\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

I then executed a request to get a fault response shielded by exception shielding. The fault response string is formatted like so: "An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: {GUID}"

I then viewed the trace log, and found no evidence of the GUID or this string.

Here is the pastebin link to the tracelog for anyone who cares to see an example of one when using ExceptionShielding.

UPDATE2:

Again, per @Jay Patel's comment, added this. I tried -1 and max int value for the maxMessageLog to ensure I'm getting the largest amount of data in that log.

<diagnostics>
  <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="2147483647" />
</diagnostics>

The log is not helpful. It includes nothing about anything even close to answering my question.

To clarify in case it's not clear above... I want to be able to capture the GUID after the "Error ID:" in the message back to the client so I can log it with the exception that is logged by the exception handler. This way clients can contact the "Administrator" as the message says with the Error ID, and actually be able to find something.

Here is the full trace enabled pastbin

.Net Solutions


Solution 1 - .Net

According to http://msdn.microsoft.com/en-us/library/ff649012.aspx:

You can also specify a Source of "{Guid}" to add the current Handling Instance ID to the Fault Contract property.

In your .config file:

<mappings>
    <add source="{Guid}" name="HandlingInstanceId" />
</mappings>

In your ValidationFault FaultContract:

[DataMember]
public Guid HandlingInstanceId { get; set; }

Note: The "{Guid}" source appears to be a special marker for the Handling Instance ID.

See also: http://entlib.codeplex.com/discussions/232049

And, the last 2 entries: http://entlib.codeplex.com/discussions/243558

Solution 2 - .Net

is message logging will be helpful? If so I guess you need something like this in your config:

<source name ="System.ServiceModel.MessageLogging" 
      switchValue="Verbose, ActivityTracing">        
<listeners>
  <add name="xml" />
</listeners>

Please notice that source name here is 'System.ServiceModel.MessageLogging' and not 'System.ServiceModel'.

For the full example please see this article: http://msdn.microsoft.com/en-us/library/dd788183.aspx

Hope this will help you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwakurthView Question on Stackoverflow
Solution 1 - .NetDaniel HolderView Answer on Stackoverflow
Solution 2 - .NetTonyView Answer on Stackoverflow