title: Javascript json object and wcf webservice bad request
body: <p>I have been successfully using wcf webservices to do some simple operations. Now I'm trying to pass a more complex object using jquery ajax post but this time I have always the same error (bad request). I have searched a lot but still could not identify the problem</p>
  
  <p>Here's what I'm trying to do:</p>
  
  <p>My interface</p>
  
  <pre><code>[OperationContract(Name = "PersonAddress")]
  [WebInvoke(UriTemplate = "AddPersonAddress/", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
  PersonAddress AddPersonAddress(PersonAddress objPA);
  </code></pre>
  
  <p>My Javascript test code:</p>
  
  <pre><code>var testObj = {
        cpostal: "Postal 1",
        address: "My address",
        zone:""
  }
  
  var objectAsJson = JSON.stringify({ objPA: testObj });
  
  $.post('../../App_Services/DataService.svc/PersonAddress/', objectAsJson, function (data) {
        alert("success");
  });
  </code></pre>
  
  <p><code>PersonAddress</code> structure</p>
  
  <pre><code>public class PersonAddress
  {
      public string cpostal { get; set; }
      public string address { get; set; }
      public string zone { get; set; }
  }
  </code></pre>
  
  <p>Chrome console post</p>
  
  <pre><code>{"objP":{"cpostal":"Postal 1","address": "My address","zone":""}}
  </code></pre>
  
  <p>according to these  articles:</p>
  
  <p><a href="http://www.primordialcode.com/blog/post/passing-json-serialized-objects-wcf-service-jquery" rel="nofollow">Link 1</a>
  <a href="http://www.primordialcode.com/blog/post/passing-json-serialized-objects-wcf-service-jquery" rel="nofollow">Link 2</a></p>
  
  <p>I have to send a string that is the JSON representation of a JS object which properties matches the parameter name of the function that i'm calling. </p>