OData的更新控制器抛出415不支持的媒体类型的错误 [英] OData update controller throwing 415 Unsupported media type error

查看:141
本文介绍了OData的更新控制器抛出415不支持的媒体类型的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OData的控制器放和邮报的行动。当我发布的内容类型:应用程序/ JSON 的,我得到了Htt presponseException与'415:不支持的媒体类型。唯一的内容类型的控制器将不会抛出一个例外是的应用程序/ x-WWW-urlformen codeD 的。但是,这不是我想要接受的内容类型。

I have an OData controller with 'Put' and 'Post' actions. When I post Content-Type:application/json, I get an HttpResponseException with '415: unsupported media type'. The only Content-Type that the controller won't throw an exception on is the application/x-www-urlformencoded. But that is not the content type that I want to accept.

为什么ODATA控制器不接受应用程序/ JSON?我没有看到在限制接受的内容类型控制器的配置什么。

Why does the odata controller not accept application/json? I don't see anything in the configuration of the controller that restricts the accepted content types.

我记得在同一code。在过去的工作。 Soemthing似乎已经倒退了。我应该在哪里看?

I remember the same code working in the past. Soemthing seems to have regressed it. Where should I look?

推荐答案

感觉LIK您在机构(即在你的行动作为一个参数声明)期望的类型是不是你的服务的EDM模型的一部分​​。

Feels lik the type that you expect in the body (i.e declared in your action as a parameter) is not part of the EDM model of your service.

例如,

HttpResponseMessage Post(Customer customer)

如果客户是不是你的EDM模型的一部分​​,网络API将抛出一个415出现这种情况的ODataControllers只有ODataMediaTypeFormatters和ODataMediaTypeFormatter支持在模型中声明的只读类型。

If customer is not part of your EDM model, web API would throw a 415. This happens as ODataControllers have only ODataMediaTypeFormatters and ODataMediaTypeFormatter supports only reading types that are declared in the model.

这篇关于OData的更新控制器抛出415不支持的媒体类型的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆