c# - error when requesting xml document as xml via web api call -
i have xml document want return via web api call.
i want allow user option of response via content negotiation.
[httpget] public httpresponsemessage get() { var doc = new xmldocument(); doc.loadxml("<myexport someproperty='some value'></myexport>"); return request.createresponse(httpstatuscode.ok, doc); }
when request accept header of application/xml error:
<error> <message>an error has occurred.</message> <exceptionmessage>the 'objectcontent`1' type failed serialize response body content type 'application/xml; charset=utf-8'.</exceptionmessage> <exceptiontype>system.invalidoperationexception</exceptiontype>
what doing wrong thought should handled via content negotiation?
the problem here returning xml (or, more accurately, xmldocument object)---so pre-empting sensible content negotiation. if client asks json, server returns xml, there's going problem.
the idea web api return poco objects , framework serializes them automagically requested format.
Comments
Post a Comment