How to Debug WCF Service Issue?

1. Change the app.config/web.config of your application that calls the WCF service by adding System.diagnostics detail as below

Code Snippet
  1. <system.diagnostics>
  2.     <sources>
  3.       <source name=System.ServiceModel switchValue=Verbose,ActivityTracing propagateActivity=true>
  4.         <listeners>
  5.           <add type=System.Diagnostics.DefaultTraceListenername=Default>
  6.             <filter type=“” />
  7.           </add>
  8.           <add name=ServiceModelTraceListener>
  9.             <filter type=“” />
  10.           </add>
  11.         </listeners>
  12.       </source>
  13.       <source name=System.ServiceModel.MessageLogging switchValue=Verbose,ActivityTracing>
  14.         <listeners>
  15.           <add type=System.Diagnostics.DefaultTraceListenername=Default>
  16.             <filter type=“” />
  17.           </add>
  18.           <add name=ServiceModelMessageLoggingListener>
  19.             <filter type=“” />
  20.           </add>
  21.         </listeners>
  22.       </source>
  23.     </sources>
  24.     <sharedListeners>
  25.       <add initializeData=MyWCFTraceLog.svclog
  26.       type=System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
  27.       name=ServiceModelTraceListenertraceOutputOptions=Timestamp>
  28.         <filter type=“” />
  29.       </add>
  30.       <add initializeData=MyWCFTraceLog.svclog
  31.           type=System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
  32.           name=ServiceModelMessageLoggingListenertraceOutputOptions=Timestamp>
  33.         <filter type=“” />
  34.       </add>
  35.     </sharedListeners>
  36.     <trace autoflush=true />
  37.   </system.diagnostics>

2. Run your application as usual until it throws the error or until the stage where you can reproduce your issue, once you are done, quit your application or take out the diagnostics section from the config file straight away so your log will not be growing too quickly/massively

3. The log file will be called as MyWCFTraceLog.svclog (as we define in the config file) and it will be located on the same folder as the executable – normally it is in the bin folder

4. How to open svclog file? Go to your program files (x86) or program files/Microsoft SDKs/Windows/v7.0A/Bin/SvcTraceViewer.exe

5. SVCTraceViewer will display you the story line of your WCF and it will help you to pinpoint the underlying issue