Debugging ADO.NET Data Services


Debugging ADO.NET Data Services
 
By default, Data Services don't return information on what's wrong when you try to execute some code, for example an update, against it. This is understandable: if you open up a data service on the web, you shouldn't be returning all important information about entities in the underlying model.
 
However, when developing a Data Service, it might be handy to get a little more information than just "An error occurred while processing this request". Here's how to achieve this...
 
You can start by setting the UseVerboseErrors on the ServiceConfiguration to true, like so:
 
public static void InitializeService(IDataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
 
This will get you the error returned by the model/database. For example, you'll see that you are inserting duplicate keys in your tables.
 
Now, this is OK if you are able to run your service. But what if it doesn't even start? You'll get the generic error: "The server encountered an error processing the request". Trying to get more info with the above method won't help you, since the service didn't even execute anything.
 
In that case, you can use the following attribute on your service class:
 
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service : DataService<NorthwindEntities>
{
...
 
These 2 options should provide you with enough information about what's going wrong with your services. Do remember to remove them when you go live with the application!
 
Source URL:
 

 

发表 @ 2009年1月11日 15:16

打 印

评论

欢迎发表评论。

您的评论:



 (不显示)


 
 
 
Please add 2 and 5 and type the answer here:
    
 

评论预览窗口:

 
«三月»
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910