title: DataService : OnStartProcessingRequest not called
body: <p>I've created a WCF DataService and for this service I require some custom authentication through the use of HTTP Headers. So i've written special functions that validate this information or throw an 403 page in the user's face when he's not allowed to see it.</p>
  
  <p>To make it easy for myself, I tried to overwrite the OnStartProcessingRequest to perform this check every call, but for some reason this function is never called by my code/WCF service :S</p>
  
  <p>This is the code of the WCF Service:</p>
  
  <pre><code>using System;
  using System.Data.Services;
  using System.Linq;
  using System.Text;
  using System.Web;
  
  namespace TenForce.Execution.Web.OData
  {
  public class TenForceApi : DataService&lt;Entities&gt;
  {
      // This method is called only once to initialize service-wide policies.
      public static void InitializeService(IDataServiceConfiguration config)
      {
          config.SetEntitySetAccessRule("*", EntitySetRights.All);
          config.UseVerboseErrors = true;
          config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
      }
  
      /// &lt;summary&gt;
      /// &lt;para&gt;This function is called prior to handeling requests. The function will perform basic
      /// authentication using the Headers supplied by the client.&lt;/para&gt;
      /// &lt;/summary&gt;
      /// &lt;param name="args"&gt;The arguments supplied for this call.&lt;/param&gt;
      protected override void OnStartProcessingRequest(ProcessRequestArgs args)
      {
          HttpContext context = HttpContext.Current;
          string customAuthHeader = ExtractAuthenticationToken(context);
          ValidateAuthentication(customAuthHeader.Split('|'), context);
          base.OnStartProcessingRequest(args);
      }
  
      #region Private Members
  
      /// &lt;summary&gt;
      /// &lt;para&gt;This function will extract the custom tenforce authentication header from the
      /// http context and return the value of that header. If the header cannot be found, a
      /// DataServiceException is thrown.&lt;/para&gt;
      /// &lt;/summary&gt;
      /// &lt;param name="context"&gt;The HttpContext object containing the custom HTTP header.&lt;/param&gt;
      /// &lt;returns&gt;The value of the header&lt;/returns&gt;
      /// &lt;exception cref="DataServiceException"&gt;No Authentication Header provided.&lt;/exception&gt;
      private static string ExtractAuthenticationToken(HttpContext context)
      {
          if (!context.Request.Headers.AllKeys.Contains(@"TenForce-Auth"))
              throw new DataServiceException(403, @"No authentication header provided.");
          return Encoding.UTF8.GetString(Convert.FromBase64String(context.Request.Headers[@"TenForce-Auth"]));
      }
  
      /// &lt;summary&gt;
      /// &lt;para&gt;Validates the authentication credentials stored inside the array.&lt;/para&gt;
      /// &lt;/summary&gt;
      /// &lt;param name="values"&gt;Array holding the required authentication details.&lt;/param&gt;
      /// &lt;param name="context"&gt;The HttpContext holding the Request and Response for this call.&lt;/param&gt;
      private static void ValidateAuthentication(string[] values, HttpContext context)
      {
          if (values.Length != 2) throw new DataServiceException(403, @"insufficient parameters provided for the authentication.");
          string username = values[0] ?? string.Empty;
          string password = values[1] ?? string.Empty;
          string database = Api2.Implementation.Authenticator.ConstructDatabaseId(context.Request.Url.AbsoluteUri);
  
          if (!Api2.Implementation.Authenticator.Authenticate(username, password, database))
          {
              AddResponseHeader(context, @"TenForce-RAuth", "DENIED");
              throw new DataServiceException(403, @"Incorrect authentication credentials.");
          }
      }
  
      /// &lt;summary&gt;
      /// &lt;para&gt;Add the specific HTTP Header to the Response of the provided HttpContext.&lt;/para&gt;
      /// &lt;/summary&gt;
      /// &lt;param name="context"&gt;The HttpContext object holding the HTTP Response.&lt;/param&gt;
      /// &lt;param name="header"&gt;The name of the header to add to the response.&lt;/param&gt;
      /// &lt;param name="value"&gt;The value of the header.&lt;/param&gt;
      private static void AddResponseHeader(HttpContext context, string header, string value)
      {
          if (!context.Request.ServerVariables[@"SERVER_SOFTWARE"].Contains(@"Microsoft-IIS/7."))
              context.Response.AddHeader(header, value);
          else
              context.Response.Headers.Add(header, value);
      }
  
      #endregion
  }
  }    
  </code></pre>
  
  <p>Anyone who could point out what the problem is?</p>