2016-08-02 133 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序列化?

回答

相關問題