in

Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Kyle Kelin on .Net

DateTime serialization issue with .NET and JSON

I was writing some client code that calls some .NET Web Services and getting a strange error. I wanted to post this just to warn people to watch out for the DateTime object and null values. I have two web services, one gets an array of Entity objects and the other takes an array of Entity objects. The array is being serialized into JSON. The get web method worked fine but when I tried to pass the array to the save web method I got the following error:

 

System.InvalidOperationException: SaveUserFavorites Web Service method name is not valid.

   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()

   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest

 request, HttpResponse response, Boolean& abortProcessing)

 

Now what sucks about this error is it is pretty generic. It pretty much means that the Ajax class cannot find a web service method that matches. So first I double checked my method names and parameters and no problem there. I'm going to fast forward through my debugging problems because this error took me awhile. The issue is one of my properties on my Entity object was a DateTime. It seems that when I was getting the JOSN array .NET serializes it wrong and then cannot read it. I really didn't need the property so I commented it out. But I did some additional research for this post and found that null is not a valid JSON value so the parser failed.

More info - http://west-wind.net/weblog/posts/398970.aspx

Tip: Firebug is critical in debugging ajax calls.

 

 

Published Aug 22 2008, 11:31 PM by KyleKelin
Filed under: ,

Comments

No Comments

Leave a Comment

(required)
(optional)
(required)
Add

About KyleKelin

Kyle Kelin has been implementing software in the Microsoft space for the past 6 years mainly as a consultant. His interests are SharePoint, .NET, JQuery, and Silverlight.
2019.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems