Answered by:
Passing JSON to WCF

Question
-
User-321479612 posted
I tried passing this json object:
{"AppStart":true,"DateFormat":"YYYY-MM-DD"}
to this service:
[OperationContract] [WebInvoke( Method = "POST", RequestFormat = WebMessageFormat.Json)] string SavePreferences(string jsonPreferences);
In this case I always get null for jsonPreferences in my serviceTuesday, March 12, 2013 4:52 AM
Answers
-
User768703680 posted
Please, use the below format
[
WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Your URI Template like for example InsertCustomer/Customer_ID"
)]
string SavePreferences(string jsonPreferences);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 12, 2013 9:57 AM
All replies
-
User-1662538993 posted
Add this after Method ='POST' or RequestFormat-
ResponseFormat = WebMessageFormat.Json
If it still does not work then try to test the service in fiddler.
You can enable some kind of logging that after hitting the method is it failing at some point.
Tuesday, March 12, 2013 8:51 AM -
User768703680 posted
Please, use the below format
[
WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Your URI Template like for example InsertCustomer/Customer_ID"
)]
string SavePreferences(string jsonPreferences);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 12, 2013 9:57 AM -
User-321479612 posted
thanks so far!! maybe it would be easier if I should just send it as a stringified JSON to WCF since it will be saved as a string in the DB?
Tuesday, March 12, 2013 11:36 AM -
User-1622227787 posted
! maybe it would be easier if I should just send it as a stringified JSON to WCF since it will be saved as a string in the DB?Yes.
Friday, March 15, 2013 9:07 AM