title: How to properly handle JSON date formatting issues for WCF Data Services
body: <p>I have implemented a WCF Data Services service like this:</p>
  
  <pre><code>[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
  public class SampleService : DataService&lt;SampleDatabase&gt;
  {
      // This method is called only once to initialize service-wide policies.
      public static void InitializeService(DataServiceConfiguration config)
      {
  
          // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
          // Examples:
          config.SetEntitySetAccessRule("SampleData", EntitySetRights.All);
          // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
          config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
          config.UseVerboseErrors = true;
      }
  }
  </code></pre>
  
  <p>However, as has been documented elsewhere, Dates are not correctly formatted by the framework JSON Serialization code.  The date is not output in a valid ISO format.  What's more astonishing is that WCF doesn't round-trip the date that is output.  So it outputs a date that looks like this: "/Date(1325376000000)/", but does not accept that same value as a valid date in return.</p>
  
  <p>Hanselman has how to fix it for WebAPI:
  <a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx" rel="nofollow">http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx</a></p>
  
  <p>And I've found similar fixes for MVC serialization:
  <a href="http://www.dalsoft.co.uk/blog/index.php/2012/01/10/asp-net-mvc-3-improved-jsonvalueproviderfactory-using-json-net/" rel="nofollow">http://www.dalsoft.co.uk/blog/index.php/2012/01/10/asp-net-mvc-3-improved-jsonvalueproviderfactory-using-json-net/</a></p>
  
  <p>Our client has specified MVC3 and .NET 4, so I think WebAPI is out, so I would like to solve this for MVC3 + WCF Data Services as found in .NET 4.  My understanding from the above fixes is that the best fix is to use JSON.NET to override the serialization/deserialization to an ISO format both .NET and Javascript understand. But I'm unable to find any guidance on overriding the JSON serialization for this.</p>
  
  <p>How can this problem be fixed specifically for WCF Data Services in .NET 4?</p>