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
Here's what I'm trying to do:
My interface
[OperationContract(Name = "PersonAddress")]
[WebInvoke(UriTemplate = "AddPersonAddress/", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
PersonAddress AddPersonAddress(PersonAddress objPA);
My Javascript test 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");
});
PersonAddress structure
public class PersonAddress
{
public string cpostal { get; set; }
public string address: { get; set; }
public string zone { get; set; }
}
Chrome console post
{"objP":{"cpostal":"Postal 1","address": "My address","zone":""}}
according to these articles:
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.
.done
? – Johan Jul 15 '13 at 23:00