title: Wcf data service - 401 error
body: <p>Im building a public web site where you need to be logged in and i have been using asmx-services up to now. Now i want to try Wcf data service instead and query the service via jQuery.</p>
  
  <p>It all works fine on localhost but once i publish my web site i get this error:</p>
  
  <pre><code>401 - Unauthorized: Access is denied due to invalid credentials.
  </code></pre>
  
  <p>I have mapped my database using Entity Data Model and then i created a wcf data service which is connected to my Data Model like this:</p>
  
  <pre><code>public class MyService : DataService&lt;MyEntities&gt;
  {
      // This method is called only once to initialize service-wide policies.
      public static void InitializeService(DataServiceConfiguration config)
      {
  
          config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
  
          config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
  
      }
  }
  </code></pre>
  
  <p>where MyEntities is specified when mapping my Entity Data Model to my database.</p>
  
  <p>As i wrote, it all works fine on localhost, i can query my service like this:</p>
  
  <pre><code>        $.ajax({
              type: "GET",
              url: "/OData/MyService.svc/Groups",
              data: "{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (data) {
  //some logic
  }});
  </code></pre>
  
  <p>but when i use the published version I get the 401-error. (i get the same error when writing the query directly in the browser)</p>
  
  <p>I'm really green using Wcf-services so i really need help to make this work, i have tried to Google but with no luck. Do i need to do any configuration in my service or in web.config or in the IIS?</p>
  
  <p>Im using IIS 7.0 and asp.net 4.0</p>