Friday, March 16, 2012

Tracing WCF Calls

I ran into an issue with one of my WCF services and was having the quite a time trying to track it down, especially since it was failing before it was getting to the actual service.  I came across a nice way of tracing the call all the way through the process.  Add the following section to your web.config file:

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

This will create a trace file that you can open up in the Microsoft Service Trace Viewer.  You can read about the details here.

Quick note – Don’t forget to remove it when you’re done!

Friday, March 9, 2012

WCF Security Debugging Trick

Not infrequently, while deploying my WCF web services to various dev and QA environments I run into security issues, where for some reason I can’t get authenticated.  I recently found an article that (WCF: "An error occurred when verifying security for the message." and Service Security Audit) that talks about how to get more info on these errors logged in the application log using the following serviceSecurityAudit behavior:

<serviceSecurityAudit 
auditLogLocation="Application"
serviceAuthorizationAuditLevel="Failure"
messageAuthenticationAuditLevel="Failure"
suppressAuditFailure="true"/>