I have a custom model binder:
public class JsonPolyModelBinder : IModelBinder
{
private readonly JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
var content = actionContext.Request.Content;
var json = content.ReadAsStringAsync().Result;
var obj = JsonConvert.DeserializeObject(json, bindingContext.ModelType, settings);
bindingContext.Model = obj;
return true;
}
}
With large payload, content.ReadAsStringAsync().Result seems to timeout my web requests.
The model binder interface forces synchronous API's...but by moving this code into my controller:
public async Task<IHttpActionResult> DoStuff()
{
var json = await Request.Content.ReadAsStringAsync();
......
}
And consuming using await over .Result - the web requests go through without a problem. I am curious as to why?