Debugging ADO.NET/WCF Data Services

Debugging ADO.NET (now WCF) Data Services can be tricky, not because of the web service part but because of the underlying persistence layer.

You can include the exception details on the error page by including this on the DataService<T> class declaration:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyService: DataService<MYENTITIES>

Alternatively, you can configure it through the Web.config file (all services, only .NET 4):

    <behavior name="">
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 

Next, you must enable verbose errors on the service configuration:

public static void InitializeService(IDataServiceConfiguration config)
config.UseVerboseErrors = true;

Also, you can override HandleException method:

protected override void HandleException(HandleExceptionArgs args)

This method is called first when an exception occurs but before it propagates to the point of crashing.

Last, you can enable the WCF logging support (more info here:

    <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> 
        <add name="ServiceModelTraceListener"/> 
    <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing"> 
        <add name="ServiceModelTraceListener"/> 
    <source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing"> 
        <add name="ServiceModelTraceListener"/> 
    <add initializeData="tracelog.svclog" 
                                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                                    name="ServiceModelTraceListener" traceOutputOptions="Timestamp"/> 

Bookmark and Share


No Comments

Add a Comment

As it will appear on the website

Not displayed

Your website