One workaround is to try to opt-out of the model binding of the parameter and use the direct deserialization model. This can be done by using a IRequestContentReadPolicy. Say your action is called 'Post':
public class ReadAsSingleObjectPolicy : IRequestContentReadPolicy
{
public RequestContentReadKind GetRequestContentReadKind(HttpActionDescriptor actionDescriptor)
{
// deserialization model
if (actionDescriptor.ActionName.Equals("Post"))
{
return RequestContentReadKind.AsSingleObject;
}
else // default model binding
{
return RequestContentReadKind.AsKeyValuePairs;
}
}
}
Here is how you can add this IRequestContentReadPolicy in the config:
config.ServiceResolver.SetService(typeof(IRequestContentReadPolicy), new ReadAsSingleObjectPolicy());
We'll try to fix this in the next release so that this scenario would just work.
maggie.ying
Member
183 Points
39 Posts
Microsoft
Re: Can't get the default XmlSerializer to support complex object
Feb 23, 2012 12:28 AM|LINK
One workaround is to try to opt-out of the model binding of the parameter and use the direct deserialization model. This can be done by using a IRequestContentReadPolicy. Say your action is called 'Post':
public class ReadAsSingleObjectPolicy : IRequestContentReadPolicy { public RequestContentReadKind GetRequestContentReadKind(HttpActionDescriptor actionDescriptor) { // deserialization model if (actionDescriptor.ActionName.Equals("Post")) { return RequestContentReadKind.AsSingleObject; } else // default model binding { return RequestContentReadKind.AsKeyValuePairs; } } }Here is how you can add this IRequestContentReadPolicy in the config:
We'll try to fix this in the next release so that this scenario would just work.
Thanks,
Maggie Ying