This comment to an answer from John Saunders, a very high-rep member of Stack Overflow, says that returning an anonymous type from a web service is a bad practice.
Assuming I have the luxury of not caring about graceful degradation of my website in the face of users with Javascript disabled, why is it bad practice to have a service method, that exists only to be called via Ajax, return an anonymous object?
It seems like such a waste to whip up a concrete type, whose sole purpose is to hold my data for a few microseconds before asp.net serializes it into JSON.
My comment was specific to SOAP web services. Consumers of SOAP web services are accustomed to working with strongly-typed data, so returning an object of anonymous type via an
objectreturn type will force them to parse the XML, which they aren’t accustomed to doing.However, for clients which do not expect (or understand) strongly-typed data, my comment does not apply. If they are already accustomed to parsing XML, or
evaling JSON, then returning an anonymous object won’t make that worse.