title: Serializing an object into the body of a WCF request using webHttpBinding
body: <p>I have a WCF service exposed with a webHttpBinding endpoint.</p>
  
  <pre><code>[OperationContract(IsOneWay = true)]
  [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Bare, 
      UriTemplate = "/?action=DoSomething&amp;v1={value1}&amp;v2={value2}")]
  void DoSomething(string value1, string value2, MySimpleObject value3);
  </code></pre>
  
  <p>In theory, if I call this, the first two parameters (value1 &amp; value 2) are taken from the Uri and the final one (value3) should be deserialized from the body of the request.</p>
  
  <p>Assuming I am using Json as the RequestFormat, what is the best way of serialising an instance of MySimpleObject into the body of the request before I send it ? This, for instance, does not seem to work :</p>
  
  <pre><code>HttpWebRequest sendRequest = (HttpWebRequest)WebRequest.Create(url);
  sendRequest.ContentType = "application/json";
  sendRequest.Method = "POST";
  using (var sendRequestStream = sendRequest.GetRequestStream())
  {
      DataContractJsonSerializer jsonSerializer = 
          new DataContractJsonSerializer(typeof(MySimpleObject));
      jsonSerializer.WriteObject(sendRequestStream, obj);
      sendRequestStream.Close();
  }
  sendRequest.GetResponse().Close();
  </code></pre>