2016-08-02 85 views
1

我有一个调用我的ApiController这是返回一个504,我只是不能解决我在做什么错...ApiController返回504 - 服务器未返回此请求的完整响应。服务器返回0字节

任何人都可以看到我的问题?

这是控制器:

public class SA_GetAllLocationsController : ApiController 
{ 
    [Route("SA_GetAllLocations")] 
    [HttpGet] 
    public List<SA_Locations> Get() 
    { 
     List<SA_Locations> result = SADatastore.Functions.Location.GetAllLocations(Settings.Default.ConnectionString); 

     return result; 
    } 
} 

这是由实体框架数据库首先生成的类SA_Locations ...

public partial class SA_Locations 
{ 
    public SA_Locations() 
    { 
     this.SA_Items = new HashSet<SA_Items>(); 
    } 

    public string LocationID { get; set; } 
    public string BuildingID { get; set; } 
    public string Name { get; set; } 
    public string Description { get; set; } 
    public string MISID { get; set; } 
    public string GPSCoords { get; set; } 
    public string QRCode { get; set; } 
    public Nullable<bool> Signable { get; set; } 
    public Nullable<bool> Auditable { get; set; } 
    public Nullable<bool> Bookable { get; set; } 
    public Nullable<bool> Entrance { get; set; } 
    public Nullable<bool> Exit { get; set; } 
    public Nullable<bool> Active { get; set; } 
    public System.DateTime LastUpdated { get; set; } 

    public virtual SA_Buildings SA_Buildings { get; set; } 
    public virtual ICollection<SA_Items> SA_Items { get; set; } 
} 

我写了一个小的“状态”功能,工作原理完美,看起来像这样:

public HttpResponseMessage Get() 
    { 
     return new HttpResponseMessage() 
     { 
      Content = new StringContent(
       "SA service is running and ready to accept connections!", 
       Encoding.UTF8, 
       "text/html" 
      ) 
     }; 
    } 

我只是不能解决为什么SA_Loc当我调试时,似乎没有错误返回ation,但是我在Fiddler中看到的响应是:

504 - 服务器没有为此请求返回完整的响应。服务器返回0字节

对象是否太复杂而无法返回?

任何帮助将非常感谢!

崔佛

UPDATE

我决定试试,看看我刚刚从控制器返回纯JSON,所以我重新写控制器如下会发生什么:

public class SA_GetAllLocationsController : ApiController 
{ 
    [Route("SA_GetAllLocations")] 
    [HttpGet] 
    public HttpResponseMessage Get() 
    { 
     List<SA_Locations> result = SADatastore.Functions.Location.GetAllLocations(Settings.Default.ConnectionString); 

     string output = JsonConvert.SerializeObject(result); 

     return new HttpResponseMessage() 
     { 
      Content = new StringContent(
       output, 
       Encoding.UTF8, 
       "application/json" 
      ) 
     }; 
    } 
} 

现在实际上抛出一个错误序列化SA_Locations对象到一个字符串!

的错误信息是:

类型的异常“Newtonsoft.Json.JsonSerializationException”发生Newtonsoft.Json.dll但在用户代码

附加信息没有被处理的:错误获取值从'System.Data.Entity.DynamicProxies.SA_Locations_720FF8784B152496318F87BCB674E344B97C0446B16D4DC2BDDC381D88C048B9'上的'SA_Buildings'。

所以,它指向的东西走向与SA_Locations,这是我说的做,是

越来越近的实体框架数据库第一生成的类....但不知道为什么这已赢得” t序列化?

回答

相关问题