WCF Troubleshooting Guide

This guide helps you diagnose and resolve common issues when building Windows Communication Foundation (WCF) services on the .NET Framework 3.5.

Common Errors

  • EndpointNotFoundException – Verify the address, binding, and service availability.
  • CommunicationException – Check firewalls, network connectivity, and security settings.
  • TimeoutException – Increase timeout values or optimize service operations.
  • SecurityNegotiationException – Ensure consistent security modes and certificates.

Diagnostic Tools

Use the following tools to gather detailed information about service behavior:

Enabling Tracing

Add the following configuration to your web.config or app.config:

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="Traces.svclog"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

Use the Service Trace Viewer to inspect the generated Traces.svclog file.

Message Logging

Configure message logging to capture inbound and outbound SOAP messages:

<system.serviceModel>
  <diagnostics>
    <messageLogging logEntireMessage="true"
                    logMalformedMessages="true"
                    logMessagesAtServiceLevel="true"
                    logMessagesAtTransportLevel="true"
                    maxSizeOfMessageToLog="2000"
                    maxMessagesToLog="5000">
      <listeners>
        <add name="msgListener"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData="Messages.svclog"/>
      </listeners>
    </messageLogging>
  </diagnostics>
</system.serviceModel>

Performance Tips

  • Reuse ChannelFactory instances instead of creating them per call.
  • Enable streaming for large data transfers.
  • Set appropriate maxBufferPoolSize and maxReceivedMessageSize.
  • Use InstanceContextMode.PerCall for stateless services.

FAQ

How do I find the exact line that caused an exception?
Enable IncludeExceptionDetailInFaults in the service behavior during debugging (never in production).
Can I use WCF with IIS 6?
Yes, but you must configure the application pool to use .NET 2.0 and enable Windows activation service (WAS) for non‑HTTP protocols.