Digging up error details can be a painful process when using ADO.NET Data Services. When something goes wrong, you’re often given a standard error message - “The server encountered an error processing the request. See server logs for more details.” Now, that message obviously offers no help at all in diagnosing the problem. This happened to me today after making a couple of changes to the entity model used by my service. I changed a few settings and renamed the model from NorthwindEntities to NorthwindEntityContext. I knew that I had almost certainly missed something when making the changes, but this generic message offered no help at all.
In order to get at the error details, I could either go sift through server logs or simply add a ServiceBehavior attribute to my service class. This attribute has a property called IncludeExceptionInFaults that can be used to serve up exception details and a stack trace when things go horribly wrong in your web services.
[ServiceBehavior(IncludeExceptionsInFaults = true)]
public class ProductService : DataService<NorthwindEntityContext>
{
public static void InitializeService(IDataServiceConfiguration config)
{
// ...
}
}
An alternative to adding the ServiceBehavior attribute to your service class is to add the <serviceDebug> setting to your service behavior configuration in web.config.
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ProductServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!-- Add endpoint configuration here -->
</services>
</system.serviceModel>
</configuration>
Now when I get an error, I’m greeted with some details that help me pinpoint exactly where the problem lies. In this case, I forgot to update my connection string when changing the name of my entity model. Easy fix.
Now I can head into web.config, update the connection string and I’m on to more productive tasks again. Crisis averted.