title: Deserialize Message object in WCF service
body: <p>In order to pass a JSON data to/from our WCF service we replaced the return type and the type of the parameters of our methods to the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx" rel="nofollow">System.ServiceModel.Channels.Message</a> one.</p>
  
  <p>This is a workaround because otherwise the default DataContractJSONSerializer will be used and it will throw an exception because our DTO objects have the IsReference setting of the DataContract attribute set to true which is not supported by this serializer.</p>
  
  <p>For example the new Read method is looking like the one below:</p>
  
  <pre><code>public Message ReadCars()
  {
      ItemInfoList&lt;CarDto&gt; cars = this.ReadCars(this.jsonItem);
      string jsonString = JsonConvert.SerializeObject(cars);
  
      return WebOperationContext.Current.CreateTextResponse(jsonString,
                  "application/json; charset=utf-8",
                  Encoding.UTF8);
  }
  </code></pre>
  
  <p>and everything is working property but the problem comes when we need to pass a Car parameter to the method like:</p>
  
  <pre><code>public Message CreateCar(Message car)
  </code></pre>
  
  <p>we are calling the service from javascript using AJAX request and passing a JSON data. </p>
  
  <p>The question is how to get this JSON data back parsed to CarDTO object?</p>
  
  <p>The problem is that the Message is storing its body as XML instead of JSON and we cannot get the real request data.</p>
  
  <p>P.S. We do not want to replace the default serializer with a custom one. We just want to manually serialize the objects to JSON, sent them using a Message and get back the objects from the Message (the problematic step).</p>