title: Restful WCF adding message header to outgoing response
body: <p>I have been trying to add a custom header with value to outgoing response messages. The value will be different for each user request.</p>
  
  <p>However I could not add the header with value using the following code:</p>
  
  <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  public class Service : IMyService
  {
      public string CommandHandler()
      {
          string s = "test";
          WebOperationContext.Current.OutgoingResponse.Headers.Add("testheader", "123456");
          return s;
      }
  }
  </code></pre>
  
  <p>If I add the following code to <code>global.asax</code>, it works but <code>testheader</code> is always <code>123</code>, I can not change the value.</p>
  
  <pre><code>protected void Application_BeginRequest(object sender, EventArgs e) 
          {
  
              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
  
              if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
              {
                  HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET");
                  HttpContext.Current.Response.AddHeader("testheader", "123");
  
                  HttpContext.Current.Response.End();
              }
          }
  </code></pre>