ServiceStack and returning a stream

Yes returning an IHttpResult will allow you to control the exact payload, Content-Type and other HTTP Headers as you wish.

Also you're not limited to returning a stream, i.e. you can use the HttpResult to return an xml string with a different Content-Type.

Here are some links that better demonstrate what's possible with ServiceStack return types:

  • How ServiceStack supports plain C# string, binary, stream, IStreamWriter, etc return types
  • An example of using CORS to set global or per-service custom HTTP Headers
  • Different ways of returning an Image from a ServiceStack service
  • Multiple options for returning HTML

You can also return a static File using a FileInfo object, with an optional parameter to return the file as an attachment which will prompt the user to download the file rather than attempt to view it in the browser with:

return new HttpResult(new FileInfo("~/static-response.xml"), asAttachment:true);