Thursday, June 12, 2008

JSON Script Ignore Tags

I've built some ASMX web services (yes these should be converted to WCF, but they work for now).  I'm starting to use these as Script Services for some ASP.NET Ajax Enabled pages.  I ran into a problem where some of the "stuff" I didn't want to have happen in some properties on the objects returned by the server were getting executed even though they were marked as [XmlIgnore()] which disables them for SOAP ASMX type web calls.  Apparently when the returned objects get serialized as JSON for a script service, they ignore the [XmlIgnore()] tag, which I guess makes sense but is rather inconvenient, in that I need to go back and do a manual search & change. Within the using System.Web.Script.Serialization namespace there is another attribute you can decorate your properties with called [ScriptIgnore()] that seems to do the trick.

-ec

No comments:

Post a Comment