I am new to Rest Services. I am passing Json object using Post method but i am not able to get the values of the class properties.
my code is like below
function SaveBook() {
var bookData = { "ISDCode": "TestISD",
"retailerCode":"RT148",
"count":"2",
"salesdata":[
{
"Serial":"3544334444",
"CustomerPhone":"98234234234",
"CustomerName":"Name1",
"CustomerInfoID":"1",
"TimeStamp":"22-May-14",
"Latitude":"10.3456",
"Longitude":"8.3453"
},
{
"Serial":"35324432324",
"CustomerPhone":"9824322333333",
"CustomerName":"Name2",
"CustomerInfoID":"2",
"TimeStamp":"21-May-14",
"Latitude":"10.3344",
"Longitude":"8.9564"
}]
}
$.ajax({
type: "POST",
url: "http://localhost/API/Service.svc/PostTertiarySales",
data: JSON.stringify(bookData),
contentType: "application/json",
dataType: "json",
//processData: true,
success: function (data, status, jqXHR) {
alert("success..." + data);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
}
</script>
In Iservice.cs [DataContract] public class TertiarySales { [DataMember] public string ISDCode { get; set; }
[DataMember]
public string retailerCode { get; set; }
[DataMember]
public string count { get; set; }
[DataMember]
public List<WCFlib.CompositeType.TertiaryData> salesdata { get; set; }
}
[DataContract]
public class TertiaryData
{
public string Serial { get; set; }
public string CustomerPhone { get; set; }
public string CustomerName { get; set; }
public Int32 CustomerInfoID { get; set; }
public DateTime TimeStamp { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public TertiaryData(string Serial, string CustomerPhone, string CustomerName, Int32 CustomerInfoID, DateTime TimeStamp, double Latitude, double Longitude)
{
this.Serial = Serial;
this.CustomerPhone = CustomerPhone;
this.CustomerName = CustomerName;
this.CustomerInfoID = CustomerInfoID;
this.TimeStamp = TimeStamp;
this.Latitude = Latitude;
this.Longitude = Longitude;
}
}
[OperationContract]
[WebInvoke(UriTemplate = "PostTertiarySales",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, Method = "POST")]
bool PostTertiarySales(WCFlib.CompositeType.TertiarySales data);
in Service.cs
public bool PostTertiarySales(WCFlib.CompositeType.TertiarySales data) {
return true;
}
Thanks
TertiaryData
class properties? – Murali Murugesan