简体   繁体   English

Web Api Get方法返回HTTP / 1.1 500 Internal Server Error

[英]Web Api Get method returns HTTP/1.1 500 Internal Server Error

I create controllers using entity. 我使用实体创建控制器。 There are severel models in my project and for every model in context "Get method" works fine, but this one, which is the same like others, did'nt. 我的项目中有严格的模型,对于上下文中的每个模型,“获取方法”都可以正常工作,但是与其他模型一样,它没有。

This is simple code: 这是简单的代码:

  // GET: api/Proizvodi
        public IQueryable<Proizvodi> GetProizvodi()
        {
            return db.Proizvodi;
        }

I tested with fidler and this is message: 我测试了fidler,这是消息:

{"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Self referencing loop detected with type 'System.Data.Entity.DynamicProxies.Proizvodi_B322A16527536C491FCFE47A9DC60617BBB3A2AAF1FABD41D99F924F0D8FE589'. Path '[0].JediniceMjere.Proizvodi'.","ExceptionType":"Newtonsoft.Json.JsonSerializationException",... {“ Message”:“发生错误。”,“ ExceptionMessage”:“” ObjectContent`1“类型未能序列化内容类型'application / json; charset = utf-8'的响应主体。”,“ ExceptionType “:” System.InvalidOperationException“,” StackTrace“:null,” InnerException“:{” Message“:”发生错误。“,” ExceptionMessage“:”检测到类型为'System.Data.Entity.DynamicProxies的自引用循环..Proizvodi_B322A16527536C491FCFE47A9DC60617BBB3A2AAF1FABD41D99F924F0D8FE589'。路径'[0] .JediniceMjere.Proizvodi'。“,” ExceptionType“:” Newtonsoft.Json.JsonSerializationException“,...

I know there are severel same question and im looking for answer but can't find. 我知道有相同的问题,我正在寻找答案,但找不到。 Is there problem with entity freimwork, problem with serialization or something else . 实体框架是否存在问题, 序列化是否存在问题或其他问题 ?? ??

Maybe this help: when i delete all records from database for this model/class, "Proizvodi", i get "HTTP/1.1 200 OK". 也许有帮助:当我从数据库中删除该模型/类“ Proizvodi”的所有记录时,我得到“ HTTP / 1.1 200 OK”。

Add thhe following to 将以下内容添加到

Global.asax

HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP .NET Web API:跟踪侦听器:HTTP / 1.1 500内部服务器错误:怎么了? - ASP .NET Web API: Trace Listeners: HTTP/1.1 500 Internal Server Error: What's wrong? 使用Web Api Http Put时内部服务器错误500 - Internal Server Error 500 when using Web Api Http Put Web Api和WCF中的HTTP发布内部服务器错误500 - Http Post Internal Server Error 500 in Web Api & WCF Web API controller GET 方法执行成功 - 但是在客户端浏览器上给出内部服务器错误(500) - Web API controller GET method executing successfully - But giving Internal server error(500) at client browser PUT Web API 出现 500 内部服务器错误 - 500 Internal server error at PUT Web API Angularjs和ASP.NET Web Api在$ http.post上导致500 Internal Server Error - Angularjs and ASP.NET Web Api cause 500 Internal Server Error on $http.post 无法在 Unity 中使用 UnityWebRequest 发布数据,它给出错误:HTTP/1.1 500 内部服务器错误 - Cannot POST data using UnityWebRequest in Unity, it gives Error: HTTP/1.1 500 Internal Server Error Web服务响应返回500内部服务器错误 - Web Service Response returns a 500 Internal Server Error Web部署代理服务返回500内部服务器错误 - Web Deployment Agent Service returns a 500 Internal Server Error 如何解决HTTP Web request 500 Internal Server错误? - How to solve HTTP Web request 500 Internal Server error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM