Atlantic BT: Our Thoughts

October 8 , 2009

Listen Up to the WCF XmlWriterTraceListener!

by Daryl Hemeon

“Welcome to WCF, don’t let the config files hit you in the a$$ on the way in or the way out.”

I have just started really digging into building some services hosted in IIS using WCF and the above quote is what the sign says on most articles and books about Microsoft’s Windows Communication Foundation (or maybe just this one). I am in the process of creating several services for our company and for the most part I have been achieving success…except for a nasty serialization issue I encountered yesterday.

I have been adding lots of trace statements to my code to make sure I have the appropriate amount of diagnostic capabilities in my suite of services to figure out just such a problem.

I execute my unit test…and of course it dies…but where?  In the client?  In the service?  Did my call even make it to my service?

I found this article on MSDN that helped me immediately solve my problem.  Enter your old friend logging and tracing…here are the settings:

<configuration>
 <system.diagnostics>
  <sources>
    <source name=“System.ServiceModel”
            switchValue=“Warning”
            propagateActivity=“true” >
      <listeners>
        <add name=“xml”/>
      </listeners>
    </source>
    <source name=“myUserTraceSource”
            switchValue=“Warning, ActivityTracing”>
      <listeners>
        <add name=“xml”/>
      </listeners>
    </source>
  </sources>
  <shareListeners>
    <add name=“xml”
         type=“System.Diagnostics.XmlWriterTraceListener”
               initializeData=“C:\logs\Traces.svclog” />
  </sharedListeners>
 </system.diagnostics>

<system.serviceModel>
  <diagnostics wmiProviderEnabled=“true”>
  </diagnostics>
 </system.serviceModel>
</configuration>

With a couple quick config settings a complete trace in XML of my problem was revealed to me — serializing an enumeration.  Now with most tracing capabilities you have to be careful about how verbose you want it to be and you don’t always want the hose running all the time, only when you have to wash the car…you dig?

The other cool item of note is that the .svclog file that gets generated comes with it’s very own reader that allows you to parse the service log.  It is called the Service Trace Viewer Tool or SvcTraceViewer.exe. Check it out!

Have fun with WCF…it is where the all the contracts are strong, all the services are good looking, and all the developers are above average. Cheers!

Leave a Reply

In a Nutshell

Since 1998, Atlantic BT has been a full service web development company that offers the tools, resources and services to get your business moving. We focus on combining new ideas, specific requirements, and years of experience into high-quality, results-oriented web solutions for small to medium sized businesses. If you want the best website possible that generates real results, let's get started.

  • Toll Free: (866) 484-0921
  • Phone: (919) 518-0670
  • Tech Support: (866) 484-0921 (option 8)
  • Fax: (919) 719-0834
Atlantic Business Technologies, Inc.
8015 Creedmoor Road, Suite 101
Raleigh, North Carolina 27613
  • Raleigh Chamber of Commerce Member
  • Cary Chamber of Commerce Member
  • Pinnacle Business Award Winner
  • Triangle Business Journal's Top 40 Under 40
  • Yahoo Search Marketing Ambassador
  • Google Adwords Qualified Company