Tomorrow night I am presenting at the Madison .Net Users group. Tonight, I am pulling my hair out, trying to get my demos to work. How far am I? Well I’m on my second demo, but the first one involves 0 programming, so I don’t think that counts.
What is was getting in my way, was a nasty System.Data.Services.Client.DataServiceRequestException, complaining of an invalid DateTime value…somewhere.
System.Data.Services.Client.DataServiceRequestException was unhandled
Message=An error occurred while processing this request.
Source=Microsoft.Data.Services.Client
StackTrace:
at System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchResponse()
at System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest()
at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
at System.Data.Services.Client.DataServiceContext.SaveChanges()
at Demo1.Program.AddEmployees() in C:\_Files\Projects\Demo1\Demo1Completed\Demo1Completed\Program.cs:line 48
at Demo1.Program.Main(String[] args) in C:\_Files\Projects\Demo1\Demo1Completed\Demo1Completed\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.Services.Client.DataServiceClientException
Message=<?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">Error reading syndication item: 'Error in line 5 position 14. An error was encountered when parsing a DateTime value in the XML.'.</message>
</error>
Source=Microsoft.Data.Services.Client
StatusCode=400
StackTrace:
at System.Data.Services.Client.DataServiceContext.SaveResult.<HandleBatchResponse>d__20.MoveNext()
InnerException:
After installing Fiddler so I could analyze the post and it’s subsequent response, I tried setting the Modified and Created properties on the Entity to DateTime.Now to give them an actual value. The Modified and Created properties are on all SharePoint list objects. I hadn’t bothered setting them, because they were of type DateTime? and I assumed that SharePoint would set them. As a matter of fact, I watched a PDC session on this very topic and blogged about it. In the demo, the only thing Pablo set was the name and the job title and posted it via CURL, and it worked.
I tried setting the values to null, but I got the same error (and why wouldn’t I). I ended up setting the values to DateTime.Min value. This allows the POST operation to succeed, and the Created and Modified values are correctly set by SharePoint.
Other notes of interest:
- Even though I installed VS 2010 with .Net 4.0, I still had to install the Ado.Net Data services 1.5 CTP2 for SharePoint 2010 to expose data via ListData.svc
- When building an application in VS 2010 with the .Net 4.0, System.Data.Services.Client is added for you when you add a Service Reference. You do not need to add a reference to Microsoft.Data.Services.Client in the CTP 2.
- Be sure to check out the different SaveChangesOptions available when you call SaveChanges for your service. The batch option really speeds things up, but if one update fails, they all fail.