title: Bad Request -Post method - JSON DateTime issue
body: <p>I have a Visual Studio (2015) project that includes a client part (Xamarin.Forms PCL) and a web service part ( WCF Rest). The web services use edmx to communicate with the database ( SQL Server 2016). JSON is used to exchange the data.</p>
  
  <p>I'm new to creating/consuming WCF Rest services. I have no issue using the GET method but I'm stuck with an issue with a POST method. </p>
  
  <p>This method is part of a service that works well: no issue for a GET based method. It works well when I test it from a URL or from my client ( PCL Xamarin.Forms).</p>
  
  <p>The POST method (my first ever) is a bit more problematic.</p>
  
  <p>It's supposed to create a new record in a table in SQL Server (2016).</p>
  
  <p>When I use Postman (<a href="https://www.getpostman.com/" rel="nofollow">https://www.getpostman.com/</a>) to test it, it already has an issue: it creates a record in the table but the object has two dates and the two dates are replaced by 1970-01-01.</p>
  
  <p>When I use my client to contact the web service:I get 'Bad Request'.</p>
  
  <p>I looked for a solution and found that instead of placing the Datetime value, it was best to place the number of milliseconds from 1970-01-01.</p>
  
  <p>I used this advice in Postman and noticed the creation of a new line worked fine. </p>
  
  <p>Body of the Postman request : </p>
  
  <pre><code>{
  "Reservation_Utilisateur_Id" : "4", 
  "Reservation_Velo_Id" : "2",
  "Reservation_DateDebut" : "\/Date(1245398693390)\/",
  "Reservation_PeriodeDebut" : "matin",
  "Reservation_DateFin" :"\/Date(1245398693390)\/", 
  "Reservation_PeriodeFin" : "matin"
   }
  </code></pre>
  
  <p>Now, I'd like to know how to get that object to send to the server . How can my object be serialized like above?</p>
  
  <p>I looked for a solution unsuccessfully.</p>
  
  <p>I keep on getting "There was an error deserializing the object of type BikeSharingService.Reservation. DateTime content '2016-08-22T00:00:00+02:00' does not start with '/Date(' and end with ')/' as required for JSON." </p>
  
  <p>Could someone please give the newbie that I am an explanation and maybe some code that works?</p>
  
  <p>Here is my code:</p>
  
  <p>My contract: </p>
  
  <pre><code>    [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "create",
          ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
      Reservation create(Reservation reservation);
  </code></pre>
  
  <p>The service method:</p>
  
  <pre><code>    public Reservation create(Reservation reservation)
      {
          using (MyEntities bse = new MyEntities())
          { 
                  Reservation re = new Reservation
                  {
                      Reservation_Utilisateur_Id = reservation.Reservation_Utilisateur_Id,
                      Reservation_Velo_Id = reservation.Reservation_Velo_Id,
                      Reservation_DateDebut = reservation.Reservation_DateDebut,
                      Reservation_PeriodeDebut = reservation.Reservation_PeriodeDebut,
                      Reservation_DateFin = reservation.Reservation_DateFin,
                      Reservation_PeriodeFin = reservation.Reservation_PeriodeFin,
                      Reservation_DemandeRecupDomCli = reservation.Reservation_DemandeRecupDomCli
  
                  };
                  bse.Reservations.Add(re);
                  bse.SaveChanges();
              return re;
          }
      }
  </code></pre>
  
  <p>On the client side : </p>
  
  <pre><code>   const string Url1 = "http://localhost:51843/ServiceReservation.svc/create";
  
     public async Task&lt;Reservation&gt; create(Reservation reservation)
      {
              string json = JsonConvert.SerializeObject(reservation);
              var client = new HttpClient();
              client.DefaultRequestHeaders.Add("Accept", "application/json");
              var response = await client.PostAsync(Url1,
                              new StringContent(
                                 json,
                              Encoding.UTF8, "application/json"));
                              return  JsonConvert.DeserializeObject&lt;Reservation&gt;(
              await response.Content.ReadAsStringAsync());            
      }
  </code></pre>
  
  <p>Then calling the method on the client side : </p>
  
  <pre><code>        Reservation re =new Reservation();
          re.Reservation_Utilisateur_Id = 4;
          re.Reservation_Velo_Id = 2;
          re.Reservation_DateDebut = DateTime.Now.Date;
          re.Reservation_PeriodeDebut = "matin";
          re.Reservation_DateFin = DateTime.Now.Date;
          re.Reservation_PeriodeFin = "matin";
          re.Reservation_DemandeRecupDomCli = 1;
  
          Reservation resultat = await reManager.create(re);
  </code></pre>
  
  <p>What I get : </p>
  
  <blockquote>
    <p>False Bad Request Method: POST, RequestUri:
    '<a href="http://localhost:51843/ServiceReservation.svc" rel="nofollow">http://localhost:51843/ServiceReservation.svc</a> /create', Version: 2.0,
    Content: System.Net.Http.StringContent, Headers: {   Accept:
    application/json   Content-Type: application/json; charset=utf-8<br>
    Content-Length: 407 }  BadRequest
    1.1</p>
    
    <p>There was an error deserializing the object of type
    BikeSharingService.Reservation. DateTime content
    '2016-08-22T00:00:00+02:00' does not start with '/Date(' and end with
    ')/' as required for JSON.</p>
  </blockquote>