Reputation: 247
I have WCF method
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
string PostNewOrder(string OrderData);
This is the json string which I am posting
{
"customerId": " ",
"langCode": "SE",
"timeZone": "38",
"orderNumber": "1122519",
"orderDate": "2016-04-13 15:56:36",
"deliveryNumber": "625615",
"devices": "000000001050840;",
"transactionId": "24",
"shipDate": "2016-04-13 16:41:31"
}
But I am getting OrderData as null in the WCF method
If I post string
"{\"customerId\":\" \",\"langCode\":\"SE\",\"timeZone\":\"38\",\"orderNumber\":\"1122519\",\"orderDate\":\"2016-04-13 15:56:36\",\"deliveryNumber\":\"625615\",\"devices\":\"000000001050840;\",\"transactionId\":\"24\",\"shipDate\":\"2016-04-13 16:41:31\"}"
It works fine but this is not a proper json , Thanks in Advance..
Upvotes: 0
Views: 757
Reputation: 161
this is an old question, but in case anyone needs an answer for this:
you will need to wrap your json string in anoter string.
i was using angular - so in my case i did this:
let doc = new FileData();
...
let jsonObj = JSON.stringify(doc); //json object string
let strObj = JSON.stringify(jsonObj); //json object string wrapped with string
Upvotes: 0
Reputation: 3726
your contract should look something like -
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json ,
UriTemplate="/post")]
string PostNewOrder(RootObject OrderData);
where RootObject
should look like -
public class RootObject
{
public string customerId { get; set; }
public string langCode { get; set; }
public string timeZone { get; set; }
public string orderNumber { get; set; }
public string orderDate { get; set; }
public string deliveryNumber { get; set; }
public string devices { get; set; }
public string transactionId { get; set; }
public string shipDate { get; set; }
}
what you are posting is a json
object representation and not a string and the WCF Runtime is expected to deserialize the content to it's equivalent strongly typed object at server.
Upvotes: 1
Reputation: 103
I think you need to remove RequestFormat and ResponseFormat from OperationContract
Upvotes: 0