I have a WCF service that expects an object as input.
[WebInvoke(Method = "POST", UriTemplate = "SaveItem", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] [OperationContract] public string SaveItem(Item item) { string retValue; using (var business = new ItemBusiness()) { retValue = business.SaveItem(item).ToString(); } return retValue; }
The class of the element is as follows.
[DataContract] public class Item { [DataMember] public string UserId { get; set; } [DataMember] public string Name { get; set; } [DataMember] public string Description { get; set; } [DataMember] public string Cost { get; set; } //[DataMember] //public string AvailableQunatity { get; set; } [DataMember] public string IsNegotiable { get; set; } [DataMember] public string LocationLat { get; set; } [DataMember] public string LocationLong { get; set; } [DataMember] public string Condition { get; set; } [DataMember] public string DeliveryType { get; set; } [DataMember] public string PostalCode { get; set; } [DataMember] public string Category { get; set; } }
I am passing json from an android app.
{"UserId": "1", "Name": "1", "Description": "1", "Cost": "1", "IsNegotiable": "1", "LocationLat": "1", " LocationLong ":" 1 "," Status ":" 1 "," DeliveryType ":" 1 "," PostalCode ":" 1 "," Category ":" 13 "}
but the WCF method gets the element as null, but not sure why.
Any help would be appreciated.
thanks.
EDIT
finally working ... changed WebMessageBodyStyle.Wrapped to WebMessageBodyStyle.Bare
source share