For some reason my wcf service is not receiving the data from my POST correctly.
It gives me this error:
The server encountered an error processing the request. The exception message is 'There was an error deserializing the object of type System.Int32. The value '' cannot be parsed as the type 'Int32'.'
The ajax request looks like this:
$.ajax({
method: "POST",
contentType: "application/json",
url: "ShopService.svc/Product",
async: false,
data: JSON.stringify({ id: 1 }),
success: function (data) {
returndata = data;
},
error: function (jqXHR, status, error) {
alert(error);
}
});
And the service code is like this:
[OperationContract]
[WebInvoke(UriTemplate = "/Product", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
public Product GetProduct(int id)
{
Product selectedProduct = db.Products.Find(id);
return selectedProduct;
}
I don't know what's going wrong here, why is the server seeing the id as empty string?