Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to WCF Rest. I want to read from a JSON object and assign key values to class variables.
Below I want to pass one JSON object inputJSonString to method writeFlatFile. It has three key values, I want those assigned to three variables of LogContact class.
I want those to use inside RestService.svc.

Input Json Object
------------------

{"key1":"value1", "key2":"value2", "key3":"value3"};

What I have tried:

<pre>//IRestService.svc

namespace RestService
{
	[OperationContract]
	[WebInvoke( Method="POST", UriTemplate="/writeFlatFile/{inputJSonString}", RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare)]
	bool SaveLog(LogDetail inputJSonString);
}
[DataContract]
public class LogDetail
{
    [DataMember]
    public int Log1 { get; set; }

    [DataMember]
    public string Log2 { get; set; }

    [DataMember]
    public string Log3 { get; set; }

} 


//RestService.svc
//----------------
	bool SaveLog(LogDetail inputJSonString)
	{
		//my program;
	}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900