Debugging ADO.NET Data Services
Interest to ADO.NET Data Services platform obviously is growing up among developers of web-services. It also confirmed when I receive e-mail letters with questions about different problems. As a rule these questions are reduced to serivce error after some actions, when serivce say about general error and not takes details. In this case services say that he stored information about error in logs.
Whether familiarly to you the given message? I think yes, if you had time to try ADO.NET Data Services in practice.
Really, ADO.NET Data Service not write any messages to log. If you need this behavior you should do it manually. What to do if you need to understand native problem of error?
It’s very simple! You need to go to static method InitializeService,which initiate web-service. In this method passed parameter contains object which implements IDataServiceConfiguration.Last has property UseVerboseErrors. To get more information about error you should set this property to True.
public static void InitializeService(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.UseVerboseErrors = true;
}
Now we call web-service again and we see error details.
Here we can already see some details and even Stack Trace! Often this information is enough. But in some cases this information has not enough. After simple operations in a reflector it is possible to understand, that all ADO.NET Data Services infrastructure is constructed over Windows Communcation Foundation, and is concrete WCF REST API. As you know, in the security goals WCF by default hides exception details. Though, we can override this behavior and explicit specify to WCF that he should show this information. In our case it more simply use ServiceBehavior attribute.
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class WebDataService1 : DataService<MvcMiniCmsEntities>
{
//...
Now WCF infrastructure will be include exception details in response and you can understand why error is appears.