title: 400 (Bad Request) or empty data when POSTing JSON string to RESTful WCF service in C#
body: <p>I got stuck sending data to a self hosted web service.
  What I got so far:</p>
  
  <p>The Service contract and implementation (btw. GET works like a charm)</p>
  
  <pre><code>[WebGet( UriTemplate = "/gast/{customer_id}/{year}/{gast_id}", ResponseFormat = WebMessageFormat.Json )]
  [OperationContract]
  public acsEintrittGast GetGastInfo( string customer_id, string year, string gast_id ) {
      acsEintrittGast gast = new acsEintrittGast();
      gast.ID = Guid.Parse( gast_id );
      gast.Bitmap = File.ReadAllBytes( dataPath + customer_id + "\\" + year + "\\" + gast_id + ".jpg" );
      return gast;
  }
  
  [WebInvoke( UriTemplate = "/gast/{customer_id}/{year}", 
      ResponseFormat = WebMessageFormat.Json, 
      RequestFormat = WebMessageFormat.Json,
      BodyStyle = WebMessageBodyStyle.Wrapped,
      Method = "POST" )]
  
  [OperationContract]
  public acsEintrittGast SetGastInfo( string customer_id, string year, acsEintrittGast GastObject /*string GastString*/ ) {
      acsEintrittGast Gast = null;
      try {
          //Gast = JsonConvert.DeserializeObject&lt;acsEintrittGast&gt;( (string)GastObject);
          File.WriteAllBytes( dataPath + customer_id + "\\" + year + "\\" + Gast.ID.ToString() + ".jpg", Gast.Bitmap.ToArray&lt;byte&gt;() );
      }
      catch {
      }
      return Gast;
  }
  </code></pre>
  
  <p>The service consumer method (running on windows phone 8.1)</p>
  
  <pre><code>public async static Task&lt;T&gt; SetRESTData( string URI, T Content ) {
      T res = default( T );
  
      HttpClient httpClient = null;
      HttpResponseMessage response = null;
      StreamReader sr  = null;
      StreamWriter writer = null;
      MemoryStream ms = null;
      try {
          httpClient = new HttpClient();
  
          string s = JsonConvert.SerializeObject( Content );
          StringContent theContent = new StringContent( s, System.Text.Encoding.UTF8, "application/json" );
  
          using( HttpRequestMessage request = new HttpRequestMessage( HttpMethod.Post, BaseURI + URI ) ) {
              request.Content = theContent;
              response = await httpClient.SendAsync( request );
          }
      }
      catch {
      }
      finally {
          if( sr != null ) {
              sr.Close();
              sr = null;
          }
          if( writer != null ) {
              writer.Close();
              writer = null;
          }
          if( ms != null ) {
              ms.Dispose();
              ms = null;
          }
          if( response != null ) {
              response.Dispose();
              response = null;
          }
          if( httpClient != null ) {
              httpClient.Dispose();
              httpClient = null;
          }
      }
      return res;
  }
  </code></pre>
  
  <p>And finally the data</p>
  
  <pre><code>[DataContract( Name = "acsEintrittGast", Namespace = "" )]
  public class acsEintrittGast {
      private Guid id = Guid.NewGuid();
      [DataMember( Name = "id", Order = 1 )]
      public Guid ID {
          get { return id; }
          set { id = value; }
      }
  
      private Byte[] bitmap = null;
      [DataMember( Name = "bitmap", Order = 1 )]
      public Byte[] Bitmap {
          get { return bitmap; }
          set { bitmap = value; }
      }
  
      private DateTime lastEntry = new DateTime( 1900, 1, 1 );
      [DataMember( Name = "lastEntry", Order = 1 )]
      public DateTime LastEntry {
          get { return lastEntry; }
          set { lastEntry = value; }
      }
  }
  </code></pre>
  
  <p>When I try to send a simple instance</p>
  
  <pre><code>acsEintrittGast gast = new acsEintrittGast();
  gast.Bitmap = new byte[80455];
  gast.ID = Guid.NewGuid();
  await acsService.SetGastInfo( ftpLicID, currentYear, gast );
  </code></pre>
  
  <p>it depends on what I try out changing some parameters I get either "400 Bad Request" or the GastObject is null.
  I also tried to declare a string as parameter, but this is also null.
  Please don't answer "use the search function". I do nothing else than searching for an answer for the last 3 days ;)
  Any hints are welcome!
  Thanks in advance...</p>