gpt4 book ai didi

asp.net-web-api - 从 OData Controller 读取的 JayData 抛出 ODataContentTypeException

转载 作者:行者123 更新时间:2023-12-04 19:58:03 27 4
gpt4 key购买 nike

我有一个 ODataController,如果我只是通过浏览器执行 GET,它似乎工作正常。但是当我使用 JayData 阅读时,我得到了 500 美元的返回。我可以看到在我的 ODataController 中调用了 GetItems() 并且它返回了一个有效的项目列表。我但是我看到了一些 ODataContentTypeException 异常被抛出,其中包含以下消息:

Additional information: A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/atom+xml;type=feed, application/atom+xml, application/json;odata=verbose, application/json' matches the content type 'application/json; odata=fullmetadata; charset=utf-8'.

然后

Additional information: A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/atom+xml;type=feed, application/atom+xml, application/json;odata=verbose, application/json' matches the content type 'application/json; odata=fullmetadata; charset=utf-8'.

然后

Additional information: A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/xml, application/json;odata=verbose, application/json' matches the content type 'application/json; odata=fullmetadata; charset=utf-8'.

最后

Additional information: A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/xml, application/json;odata=verbose, application/json' matches the content type 'application/json; odata=fullmetadata; charset=utf-8'.

我假设这些是我返回 500 的原因,但似乎没有办法确定。根据 Chrome,正在发送的请求请求以下内容:

Accept:application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, /;q=0.1

Accept-Encoding:gzip,deflate,sdch

收到的只是一个带有 500 错误的空响应。还有其他人遇到这个问题吗?

Accept-Language:en-US,en;q=0.8,en-CA;q=0.6

最佳答案

为了使该解决方案有意义,需要更多信息:使用 MVC5、WebAPI 2.0 和 OData nuget 包版本 5.0

出于某种原因,JayData 正在尝试使用 OData v2。因此,为了修复它,我仔细研究了源代码,发现您可以指定 V3。

更改上下文配置以包含 maxDataServiceVersion: "3.0"。

来自这里:

dbContext = new MyEntities({ name: 'oData', oDataServiceHost: '/odata' }));

对此:

dbContext = new MyEntities({ name: 'oData', oDataServiceHost: '/odata', maxDataServiceVersion: '3.0' }));

这对我有用。

如果 JayStack 能够记录可用的配置选项,那就太好了。

关于asp.net-web-api - 从 OData Controller 读取的 JayData 抛出 ODataContentTypeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21105871/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com