I have just started to use ServiceStack which is an amazing library.
However, I have a business requirement where we must return xml and json where the xml must be in specific format.
For example we have existing customers that expect xml of the format:
<service name="service1" type="audio" .../>
so basically a bunch of attributes.
I know that ServiceStack uses concepts of DTOs and uses the DataContractSerializer which returns xml elements rather than in the form above with xml attributes.
I still want to use the DTOs for requests (passing in application/xml or application/json in the Accept header) and I can then create my own xml strings or json strings and then return them as :
string result = "....xml or json string...";
return new MemoryStream(Encoding.UTF8.GetBytes(result));
where the result string could be an xml string or a json string.
I noticed in fiddler the response Content-Type as text/html.
With the approach I am using, am I violating any REST principles? Will there be issues with the Content-Type as it is currently (text/html)?
If I do use this approach it does solve the business requirements.
Edit
I found that I can return a httpResult as :
return new HttpResult(
new MemoryStream(Encoding.UTF8.GetBytes(result)), "application/xml");
which gives the correct content-type.
So, is this the right way or will I have issues if I go down this route?