title: ServiceStack and returning a stream
body: <p>I have just started to use ServiceStack which is an amazing library.</p>
  
  <p>However, I have a business requirement where we must return xml and json where the xml must be in specific format.</p>
  
  <p>For example we have existing customers that expect xml of the format:</p>
  
  <pre><code>&lt;service name="service1" type="audio" .../&gt;
  </code></pre>
  
  <p>so basically a bunch of attributes.</p>
  
  <p>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.</p>
  
  <p>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 :</p>
  
  <pre><code>string result = "....xml or json string...";
  return new MemoryStream(Encoding.UTF8.GetBytes(result));
  </code></pre>
  
  <p>where the result string could be an xml string or a json string.</p>
  
  <p>I noticed in fiddler the response Content-Type as text/html.</p>
  
  <p>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)?</p>
  
  <p>If I do use this approach it does solve the business requirements.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I found that I can return a httpResult as :</p>
  
  <pre><code>return new HttpResult(
           new MemoryStream(Encoding.UTF8.GetBytes(result)), "application/xml");
  </code></pre>
  
  <p>which gives the correct content-type.</p>
  
  <p>So, is this the right way or will I have issues if I go down this route?</p>