2012-06-27 77 views
4

我遇到WebAPI問題返回空500.WebAPI空500錯誤

這裏是數據類。

public class Comment 
{ 
    public int Id { get; set; } 
    public string Content { get; set; } 
    public string Email { get; set; } 
    public bool IsAnonymous { get; set; } 

    public int ReviewId { get; set; } 
    public Review Review { get; set; } 
} 
public class Review 
{ 
    public int Id { get; set; } 
    public string Content { get; set; } 

    public int CategoryId { get; set; } 
    public string Topic { get; set; } 
    public string Email { get; set; } 
    public bool IsAnonymous { get; set; } 

    public virtual Category Category { get; set; } 
    public virtual ICollection<Comment> Comments { get; set; } 
} 

這裏的代碼來從ReviewRepository.cs

public Review Get(int id) 
{ 
    return _db.Reviews.Include("Comments").SingleOrDefault(r => r.Id == id); 
} 

而且從ReviewController.cs

public HttpResponseMessage Get(int id) 
{ 
    var category = _reviewRepository.Get(id); 
    if (category == null) 
    { 
     return Request.CreateResponse(HttpStatusCode.NotFound); 
    } 
    return Request.CreateResponse(HttpStatusCode.OK, category); 
} 

不管我做什麼的代碼,響應從/ API /評論回/ 1是500錯誤。調試時,所有加載的評論都是正確的。

我試過GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;,但這並沒有幫助。我在這裏虧本!

回答

0

我遇到了同樣的問題。除了GlobalConfiguration策略之外,您可能還需要在web.config中包含以下內容。

<system.webServer> 
    <httpErrors existingResponse="PassThrough" /> 
</system.webServer> 
+0

不過沒什麼通過只是一個空洞的500 :( – jcreamer898

0

這可能是序列號爲ICollection<Comment> CommentsCategory Category