wcf web service in post method, object properties are null, although the object is not null

Posted by Abdalhadi Kolayb on Programmers See other posts from Programmers or by Abdalhadi Kolayb
Published on 2013-10-26T07:41:10Z Indexed on 2013/10/26 10:12 UTC
Read the original article Hit count: 541

Filed under:
|

i have this problem in post method when i send object parameter to the method, then the object is not null, but all its properties have the default values.

here is data module: [DataContract] public class Products { [DataMember(Order = 1)] public int ProdID { get; set; } [DataMember(Order = 2)] public string ProdName { get; set; } [DataMember(Order = 3)] public float PrpdPrice { get; set; } }

and here is the interface:

[OperationContract] [WebInvoke( Method = "POST", UriTemplate = "AddProduct", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json)] string AddProduct([MessageParameter(Name = "prod")]Products prod);

public string AddProduct(Products prod) { ProductsList.Add(prod); return "return string"; }

here is the json request: Content-type:application/json {"prod":[{"ProdID": 111,"ProdName": "P111","PrpdPrice": 111}]}

but in the server the object received: {"prod":[{"ProdID": 0,"ProdName": NULL,"PrpdPrice": 0}]}

© Programmers or respective owner

Related posts about web-services

Related posts about wcf