How do you change the return format

Sep 15, 2011 at 2:26 PM

It does not appear to respect 

Accept: application/xml

or 

ContentType: application/xml

So how do I allow for that, the json stuff is nice, but I want to be able to serialize the results in the format the caller requests. I would also like to handle ?$format=xml etc. 

I can do all that in WCF, I can also handle the Date formatting issue in WCF, but it is nasty and involves [DataContract] and [DataMember] attributes where I would just rather return POCOs like your framework allows.

 

If there is no way to do the xml today, that is fine, if you can point me toward where you decide what to do, I can look at adding it myself and posting something back.

 

Thanks

Jeff

Coordinator
Sep 15, 2011 at 5:09 PM

Currently I don't support xml at all.  This was a library I developed for internal use at my company, and we only use json for transport.  The RestHttpHandler class has a public JsonSerializer property, so each service class has it's own serializer that you can access and set up however you'd like, but it's still the Json.NET serializer.  You may want to take a look at the private writeJsonResponse methods in RestHttpHandler.cs.  I'm not 100% sure that those are the only places things are sent to the client though.  Look for anything that does Response.Write or m_response.Write.  I would make an effort to support xml, but the purpose of the library is really to be a 1-trick-pony for http services that use json.

Nov 23, 2011 at 1:03 PM

Have any of you guys made any progress on this one ?
What needs to be done in order to support also xml input (deserialization) ? 

Coordinator
Nov 23, 2011 at 7:29 PM

If you need to use xml for input/output, I would not recommend using RestCake.  Take a look at the WCF Web API.

http://wcf.codeplex.com/wikipage?title=WCF%20HTTP

The WCF and ASP.NET teams at MS have merged.  You can currently create REST services using MVC, WCF (old school) or the WCF Web API (new way, still being developed.  That's what I linked to).  All of those efforts are merging, and the WCF Web API will be the new model.  If you need to support different formats, that's your best bet.  They have some great examples to get you started.

Nov 24, 2011 at 2:16 AM

Yeah I have switched to WCF HTTP, it is much more built out. I have been able to get all the formats I need and even added code to support $format=xml/json/etc. like oData has in the spec as well.

 

I cant recommend it highly enough.