In the hopes of supplying more metadata to my application, I wanted to wrap some extra information around my database queries (using plain on SQL data access, no Entity Framework or other ORMs).
I have an APIQueryResult
object set up as:
string Status { get; set; }
string[] Errors { get; set; }
object[] Data { get; set;}
The Data
is an array of my POCO object(s).
If I request JSON, then everything serializes just fine, including my metadata + object data. However, if I request XML, then I get the following error:
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
Note: This idea was inspired by Filip W (http://www.strathweb.com/2012/06/extending-your-asp-net-web-api-responses-with-useful-metadata/ ) but I didn't want to get as complicated as writing HttpHandlers, etc.
Is there a better way to provide at least error information back to the client if I can't return a normal class, or IEnumerable/List of class instances?
Thanks!