“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!
