I using C# with Web API. I have this server method:
[System.Web.Http.HttpPost]
public HttpResponseMessage Test(CompareOutput model)
{
return new HttpResponseMessage(HttpStatusCode.OK);
}
This is my data-model:
public class CompareOutput
{
public CompareOutput(int wc, int source_start, int source_end, int suspected_start, int suspected_end)
{
this.WordsCount = wc;
this.SourceStartChar = source_start;
this.SourceEndChar = source_end;
this.SuspectedStartChar = suspected_start;
this.SuspectedEndChar = suspected_end;
}
public CompareOutput()
{
}
[JsonProperty("wc")]
public int WordsCount { get; set; }
[JsonProperty("SoS")]
public int SourceStartChar { get; set; }
[JsonProperty("SoE")]
public int SourceEndChar { get; set; }
[JsonProperty("SuS")]
public int SuspectedStartChar { get; set; }
[JsonProperty("SuE")]
public int SuspectedEndChar { get; set; }
public override string ToString()
{
return string.Format("{0} -> {1} | {2} -> {3}", this.SourceStartChar, this.SourceEndChar, this.SuspectedStartChar, this.SuspectedEndChar);
}
}
Now, I trying to call this method with this data (placed in BODY of the HTTP request):
{
"wc":11,
"SoS":366,
"SoE":429,
"SuS":393,
"SuE":456
}
This call isn't working. All the int
members getting defualt values ("0").
When I trying to send this HTTP-BODY, it's working good:
{
"WordsCount":11,
"SourceStartChar":366,
"SourceEndChar":429,
"SuspectedStartChar":393,
"SuspectedEndChar":456
}
I can understand from that - alternative names (which defined in the model with JsonPropertry
attribute) isn't working.
How can I solve it?
Thank you.