.NET web service gets null object

I’m trying to save an object using ajax call and .NET REST web service but I get null object on .NET side. Please help me to find out what’s the issue.

C# Object:

[DataContract]
public class Customer
{
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public string Name { get; set; }

Web service:

        [WebInvoke(UriTemplate = "SaveCustomer", BodyStyle = WebMessageBodyStyle.Wrapped,
           RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
           Method = "POST")]
        [OperationContract]
        bool SaveCustomer(Customer c);

AJAX Call:

var type = "POST";
var url = "/WS/Service.svc/SaveCustomer";
var contentType = "application/json; charset=utf-8";
var dataType = "json";
var data = '{ "c:":{"Id": "1", "Name": "myname"}';
var processData = true;

$.ajax({
    type: type, 
    url: url, 
    data: data, 
    contentType: contentType, 
    dataType: dataType, 
    processdata: processData, 
    success: function (msg) {
        alert(msg.SaveCustomerResult);
    },
    error: function (error) {
        alert('error');
    }
});

using that I get null when debugging:

public bool SaveCustomer(Customer c)
{
    return true;
}


Source: .net

Leave a Reply