I must create webhook endpoint that will consume JSON messages.
Messages is send as x-www-form-urlencoded in form:
key = json
value = {"user_Id": "728409840", "call_id": "1114330","answered_time": "2015-04-16 15:37:47"}
as shown in PostMan:
request looks like this:
json=%7B%22user_Id%22%3A+%22728409840%22%2C+%22call_id%22%3A+%221114330%22%2C%22answered_time%22%3A+%222015-04-16+15%3A37%3A47%22%7D
To get values from request as my class (model) I must create temporary object containing single string property:
public class Tmp
{
public string json { get; set; }
}
and method inside my controller that consumes that request:
[AllowAnonymous]
[Route("save_data")]
[HttpPost]
public IHttpActionResult SaveData(Tmp tmp)
{
JObject json2 = JObject.Parse(tmp.json);
var details = json2.ToObject<CallDetails>();
Debug.WriteLine(details);
//data processing
return Content(HttpStatusCode.OK, "OK", new TextMediaTypeFormatter(), "text/plain");
}
As You can see Tmp class is useless.
Is there a way to get request data as this class:
public class CallDetails
{
public string UserId { get; set; }
public string CallId { get; set; }
public string AnsweredTime { get; set; }
}
I'm aware of IModelBinder class, but before I start I'd like to know if there is an easier way.
I can't change web-request format, by format I mean that is will always be POST containing single key - JSON yhat has json string as value.

asynckeyword just to doTask.Delay(1)Task.Delay(1)sorry if it is confusing.JSONand value contains json string