56

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

Quonux
  • 2,975
  • 1
  • 24
  • 32
wakurth
  • 1,644
  • 1
  • 23
  • 39
  • So, I already put up a bounty once on this one. If someone strolls along with an answer at some point, I will do what I can to give up a 50 point bounty to them (I'm not even sure if you can do this, but if an answer comes in and I like it, I will post a bounty and reward that person... if that's a no no here on stack...well...I will give you a virtual high five and say thank you :) – wakurth May 28 '13 at 18:49
  • 1
    Not that it would help but have you tried logging using Tracing in [WCF Tracing](http://msdn.microsoft.com/en-us/library/ms733025.aspx) Do you see same error ID here? – Jay Patel Jul 18 '13 at 05:28
  • I have not. I will check it out. The company I work for does have a contact at MS, that I have submitted this question to, and was told they would pass it on the the EntLib team at MS and get me an answer. In the mean time, I will try out the WCF Tracing and see if it helps point me in the direction of how to capture this value on the server side. thanks. – wakurth Jul 18 '13 at 17:24
  • Yes the sole purpose of WCF Tracing is to log all the requests/responses/errors. Let me know how it goes. – Jay Patel Jul 18 '13 at 19:45
  • The responding fault string is "An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: {GUID}" and it is no where to be found in the trace logs. – wakurth Jul 26 '13 at 22:09
  • Setup your service as in this [answer](http://stackoverflow.com/questions/1933956/wcf-tracing-how-i-can-get-the-exact-reason-for-closing-connection) – Jay Patel Jul 30 '13 at 19:28

2 Answers2

2

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

Daniel Holder
  • 111
  • 1
  • 5
  • This adds it (the handling instance id) to the validation fault itself returned to the consumer, but does not help me with my question, which is how to capture the "Error ID: {GUID}". Capturing that GUID is specifically what I've outlined in the question – wakurth Oct 20 '13 at 04:06
1

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.

Tony
  • 7,345
  • 3
  • 26
  • 34