How to return a IList in json format in a WCF RESTful service? -
is possible have method signature in wcf 3.5 service (offer custom class datacontractattribute , datamemberattribute):
[operationcontract] [webget(uritemplate = "getoffers", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.bare)] ilist<offer> getoffers();
because if type in web browser corresponding url, serialization error (i think it's because ilist doesn't have serializable attribute json serializer unable serialize it).
the workaround use method signature one:
[operationcontract] [webget(uritemplate = "getoffers", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.bare)] list<offer> getoffers();
resulting in same serialized output (a simple json array), first 1 works xml, wondering if there way make work in json, keeping same signature.
edit: ok not work xml serialization either, behavior seems normal. question still stands, possible keep signature , change serializer behavior make work? how?
i believe need add hard collection types use list of known types. see http://msdn.microsoft.com/en-us/library/ms730167.aspx conceptual explanation, see http://msdn.microsoft.com/en-us/library/ms751512.aspx sample, , see http://msdn.microsoft.com/en-us/magazine/gg598929.aspx well-written msdn magazine article.
also, please see top 2 answers here: how configure wcf known types programmatically?
Comments
Post a Comment