title: Change the json DateTime serialization in WCF 4.0 REST Service
body: <p>I need to replace the DateTime serialization for JSON in WCF REST Self Hosted service. Right now, I'm using something like the following code to do it, but it's definitely not the way to go since it requires manipulating each class. </p>
  
  <pre><code>[DataContract]
  public class Test
  {
      [IgnoreDataMember]
      public DateTime StartDate;
  
      [DataMember(Name = "StartDate")]
      public string StartDateStr
      {
          get { return DateUtil.DateToStr(StartDate); }
          set { StartDate = DateTime.Parse(value); }
      }
  }
  </code></pre>
  
  <p>where my utility function DateUtil.DateToStr does all the formatting work.</p>
  
  <p>Is there any easy way to do it without having to touch the attributes on my classes which have the DataContract attribute? Ideally, there would be no attributes, but a couple of lines of code in my configuration to replace the serializer with one where I've overridden DateTime serialization.</p>
  
  <p>Everything that I've found looks like I have to replace huge pieces of the pipeline.</p>
  
  <p>This article doesn't appear to apply because in I'm using WebServiceHost not HttpServiceHost, which not part of the 4.5.1 Framework.</p>
  
  <p><a href="https://stackoverflow.com/questions/9827933/json-net-serializer-for-wcf-rest-services">JSON.NET Serializer for WCF REST Services</a></p>