Model binding would not work in this kind of scenario. We have provided a flag to go through a de-serialization approach for these kind of scenarios. The whole body is deserialized as it used to in WebAPI preview 6.
public class ReadAsSingleObjectPolicy : IRequestContentReadPolicy
{
public RequestContentReadKind GetRequestContentReadKind(HttpActionDescriptor actionDescriptor)
{
//Serialization approach
if (actionDescriptor.ActionName.Equals("PostDC_PersonAsKeyValuePair"))
{
return RequestContentReadKind.AsSingleObject;
}
else //Default
{
return RequestContentReadKind.AsKeyValuePairs;
}
}
}
It can be configured on service's HttpConfiguration object as
config.ServiceResolver.SetService(typeof(IRequestContentReadPolicy), new ReadAsSingleObjectPolicy());
Marked as answer by pgbross on Feb 21, 2012 08:15 AM
dravva
Member
142 Points
31 Posts
Microsoft
Re: Model binding complex dto exception with "Cannot create an abstract class"
Feb 20, 2012 06:47 PM|LINK
Model binding would not work in this kind of scenario. We have provided a flag to go through a de-serialization approach for these kind of scenarios. The whole body is deserialized as it used to in WebAPI preview 6.
public class ReadAsSingleObjectPolicy : IRequestContentReadPolicy { public RequestContentReadKind GetRequestContentReadKind(HttpActionDescriptor actionDescriptor) { //Serialization approach if (actionDescriptor.ActionName.Equals("PostDC_PersonAsKeyValuePair")) { return RequestContentReadKind.AsSingleObject; } else //Default { return RequestContentReadKind.AsKeyValuePairs; } } }