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):
<serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors>
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) { base.HandleException(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:
<system.diagnostics> <sources> <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> <listeners> <add name="ServiceModelTraceListener"/> </listeners> </source> <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing"> <listeners> <add name="ServiceModelTraceListener"/> </listeners> </source> <source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing"> <listeners> <add name="ServiceModelTraceListener"/> </listeners> </source> </sources> <sharedListeners> <add initializeData="tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp"/> </sharedListeners> </system.diagnostics>