I made a fairly simple mistake. In Fiddler, I created a POST. Notice in "FileFullpath", I used a single backslash instead of two.
My Web API model is defined like this ...
public class GTMetadataModel
{
public int Id { get; set; }
public string ComputerId { get; set; }
public string UserId { get; set; }
public string FileFullpath { get; set; }
public string Version { get; set; }
public string[] Categories { get; set; }
public double[] Scores { get; set; }
}
My Web API controller is defined like this...
public HttpResponseMessage PostGTMetadata(GTMetadataModel newentry)
{
... // handle null parameter and return error here.
var response = Request.CreateResponse<GTMetadataModel>(HttpStatusCode.Created, newentry);
return response;
}
When I run the Web API and send the Fiddler POST, "newentry" is null. It took a little time before I realized I needed two backslashes. I changed it to two and then "newentry" was correct.
So, clearly the problem was bad data being supplied, but where and how in my server side code would I be able to detect the bad Json data?
Update: Mark's answer is accepted. Because the referenced post is a good example of a robust, elegant approach. But, for those who just want the simple answer, the referenced post uses "this.ModelState" to identify the problem with the parsed data. I could add the following code to my Post handler method (more likely, I will adapt something from the answer Mark references).
if(ModelState.IsValid == false)
{
var errors = ModelState
.Where(s => s.Value.Errors.Count > 0)
.Select(s => s.Key + ": " + s.Value.Errors.Select(t=>t.Exception.Message).Aggregate((a,b) => a + "\n" + b))
.Aggregate((a, b) => a + "\n" + b);
Debug.Print(errors);
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, errors);
}