When developing your service, you might run into some issues and you want to debug your service. imagine that you are inserting data into the store using Astoria and you start getting dataservicetions in your client code. the normal error message wocould be ......
<? XML version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
< Error Xmlns = "Http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" >
< Code > </ Code >
< Message XML: Lang = "En-us" > An error occurred while processing this request. </ Message >
</ Error >
While debugging the service, you wowould need more information that just this generic error message. to switch to the dev error mode, you can use the following config settings.
1) set useverboseerrors to true in the serviceconfiguration
Public Class Yoruservice: dataservice < Yourprovider > {
Public Static Void Initializeservice (idataserviceconfiguration config ){
Config. useverboseerrors = True ;
......
}
......
}
Once this mode is setup, your error messages look like this ......
<? XML version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
< Error Xmlns = "Http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" >
< Code > </ Code >
< Message XML: Lang = "En-us" > An error occurred while processing this request. </ Message >
< Innererror Xmlns = "Xmlns" >
< Message > An error occurred while updating the entries. See the innerexception for details. </ Message >
< Type > System. Data. updateexception </ Type >
< Stacktrace > At system. Data. Mapping. Update. Internal. updatetranslator. Update (ientitystatemanager statemanager, ientityadapter adapter) & # XD;
At system. Data. Objects. objectcontext. savechanges (Boolean acceptchangesduringsave) & # XD;
At system. Data. Services. providers. objectcontextserviceprovider. savechanges () & # XD;
At system. Data. Services. dataservice '1. handlenonbatchrequest (requestdescription description) & # XD;
At system. Data. Services. dataservice '1. handlerequest () </ Stacktrace >
< Internalexception >
< Message > Violation of primary key constraint 'pk _ region '. Cannot insert duplicate key in object 'dbo. region'. & # XD;
The statement has been terminated. </ Message >
< Type > System. Data. sqlclient. sqlexception </ Type >
< Stacktrace > At system. Data. sqlclient. sqlconnection. onerror (sqlexception exception, Boolean breakconnection) & # XD;
At system. Data. sqlclient. tdsparser. throwexceptionandwarning (tdsparserstateobject stateobj) & # XD;
At system. Data. sqlclient. tdsparser. Run (runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj) & # XD;
At system. Data. sqlclient. sqlcommand. finishexecutereader (sqldatareader ds, runbehavior, string resetoptionsstring) & # XD;
At system. Data. sqlclient. sqlcommand. runexecutereadertds (commandbehavior describehavior, runbehavior, Boolean returnstream, Boolean async) & # XD;
At system. Data. sqlclient. sqlcommand. runexecutereader (commandbehavior describehavior, runbehavior, Boolean returnstream, string method, dbasyncresult result) & # XD;
At system. Data. sqlclient. sqlcommand. internalexecutenonquery (dbasyncresult result, string methodname, Boolean sendtopipe) & # XD;
At system. Data. sqlclient. sqlcommand. executenonquery () & # XD;
At system. Data. Mapping. Update. Internal. dynamicupdatecommand. Execute (updatetranslator translator, entityconnection connection, Dictionary '2 identifiervalues, list '1 generatedvalues) & # XD;
At system. Data. Mapping. Update. Internal. updatetranslator. Update (ientitystatemanager statemanager, ientityadapter adapter) </ Stacktrace >
</ Internalexception >
</ Innererror >
</ Error >
This works well when you have a working service all prepped up and ready to go. But, what do you do when your service won't even start? If the service fails to initialize due to some error, you get the generic WCF error message, which is seldom useful. The error message wocould look like this ......
The reason you see this and not the pretty formatted error message from Astoria is that the Astoria framework never initialized the service and failed in the WCF pipeline. to see the error at this layer, you will need
2) Configure your servicebehavior with the specified deexceptiondetailinfaults attribute.
Via code:
[System. servicemodel. servicebehavior (includeexceptiondetailinfaults = True )]
Public Class Yourservice: dataservice < Yourprovider >
Via config:
< System. servicemodel >
< Services >
< Service Name = "Servicenamespace. serviceclassname" Behaviorconfiguration = "Debugenabled" >
</ Service >
</ Services >
< Behaviors >
< Servicebehaviors >
< Behavior Name = "Debugenabled" >
< Servicedebug Includeexceptiondetailinfaults = "True" />
</ Behavior >
</ Servicebehaviors >
</ Behaviors >
< Servicehostingenvironment Aspnetcompatibilityenabled = "True" />
</ System. servicemodel >
After setting this config, this is what the error looks like ......
From: http://blogs.msdn.com/ B /phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx