Blog‎ > ‎

Debugging WCF

posted Feb 8, 2010, 11:26 AM by Rene Rasmussen   [ updated Feb 8, 2010, 1:26 PM ]
I have been using wcf in several projects and I love the possibilities provided by wcf to connect servers and clients simply by specifying the right setup in the config files. But debugging connections specified in wcf configurations doesn’t really follow the old school debugging scheme where we add a breakpoint and step into the source.
Some weeks ago I was working on a client server system (Eqatec Analytics) where the services have been running perfectly for several months. But suddenly we did notice a specific call failed when a large amount of data was requested. As I looked into the issue I found the server side seems to be running fine. I monitored the communication using firebug and the call consistently failed when the data received exceed ~1 MB. My first thought was the data size limits specified in the bindings, but they had more than enough space for sending my 1 MB of data – both on server side and on client side.
      <binding name="ServicesBinding" maxReceivedMessageSize="3000000" 
        <readerQuotas maxArrayLength="3000000" maxStringContentLength="3000000"/>

Then I decided I had to investigate the possibilities for debugging WCF configurations.
The first think to notice is the possibility to add trace listeners which would log errors and warnings to a file.
    <trace autoflush="true" />
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Information, Warning, ActivityTracing"
          <add name="myTracer" />
      <source name="System.ServiceModel"
              switchValue="Information, Warning, ActivityTracing"
          <add name="myTracer" />
      <source name="System.Runtime.Serialization">
          <add name="myTracer" />
      <add name="myTracer"
           initializeData="c:\log\Traces.svclog" />

After studying the log-files and further “goggling” I found the problem and it wasn’t actually related to the data size, but the number of data items to be serialized. The problem was solved with this setup
        <behavior name="Analytics.WCF.Services.StandardServiceBehavior">
          <dataContractSerializer maxItemsInObjectGraph="655360"/>
So the problem was solved and everybody are happy, but the really lesson learned was how to debug this very strong tool we have in WCF.

I include a few links for more information on debugging WCF: