title: REST Stream's OutgoingResponse.ContentType is ignored, always shows "application/xml" on receiving browser
body: <p>I have a self-hosted WCF REST/<code>webHttpBinding</code>-endpoint-bound service.  I have a few streams of different content types that it serves.  The content itself is delivered correctly, but any <code>OutgoingResponse.ContentType</code> setting seems to be ignored and instead delivered as <code>"application/xml"</code> every time.  </p>
  
  <p>Browsers seems to <em>get over it</em> for javascript and html (depending on how it's to be consumed), but not for css files which are interpreted more strictly.  CSS files are how I realized the problem but it's a problem for all Streams.  Chromebug and IE developer tools both show <code>"application/xml"</code> regardless of what I put in the serving code for a content type.  I've also tried setting the content type header as a <code>Header</code> in <code>OutgoingResponse</code> but that makes no difference and it probably just a long way of doing what OutgoingResponse.ContentType does already.</p>
  
  <pre><code>[OperationBehavior]
  System.IO.Stream IContentChannel.Code_js()
  {
      WebOperationContext.Current.OutgoingResponse.ContentType = "text/javascript;charset=utf-8";
  
      var ms = new System.IO.MemoryStream();
  
      using (var sw = new System.IO.StreamWriter(ms, Encoding.UTF8, 512, true))
      {
          sw.Write(Resources.code_js);
          sw.Flush();
      }
  
      ms.Position = 0;
  
      return ms;
  }
  </code></pre>
  
  <p>This behavior is added:</p>
  
  <pre><code>var whb = new WebHttpBehavior
  {
      DefaultBodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.WrappedRequest,
      DefaultOutgoingRequestFormat = System.ServiceModel.Web.WebMessageFormat.Json,
      DefaultOutgoingResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json,
      HelpEnabled = false
  };
  </code></pre>
  
  <p>I've tried setting <code>AutomaticFormatSelectionEnabled = true</code> and <code>false</code> just in case because it came up in google searches on this issue, but that has no effect on this.</p>
  
  <p>I'm finding enough <a href="http://www.code-magazine.com/Article.aspx?quickid=080014" rel="nofollow">articles</a> that show Stream and ContentType working together to confuse the heck out of me as to why this isn't working.  I believe that the <code>Stream</code> is only intended to be the body of the response, not the entire envelope.</p>
  
  <p>My .svclog doesn't show anything interesting/relevant that I recognize.</p>
  
  <p>============</p>
  
  <p>I can confirm in Fiddler2 that the headers are being delivered as shown in the browser.</p>
  
  <pre><code>...
  Content-Type: application/xml; charset=utf-8
  Server: Microsoft-HTTPAPI/2.0
  ...
  </code></pre>