我打电话给我的ApiController,它返回了504,我无法弄清楚我做错了什么......
有人能看到我的问题吗?
这是控制器:
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; }
}
我写了一个很小的状态&#34;功能完美,看起来像这样:
public HttpResponseMessage Get()
{
return new HttpResponseMessage()
{
Content = new StringContent(
"SA service is running and ready to accept connections!",
Encoding.UTF8,
"text/html"
)
};
}
我无法弄清楚为什么在调试时SA_Locations似乎没有错误返回,但我在Fiddler中看到的响应是:
504 - 服务器未返回此请求的完整响应。服务器返回0字节
对象是否太复杂而无法返回?
非常感谢任何帮助!
崔佛
更新
我决定尝试看看如果我从控制器返回纯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对象序列化为字符串的错误!
错误消息是:
类型&#39; Newtonsoft.Json.JsonSerializationException&#39;的例外情况发生在Newtonsoft.Json.dll但未在用户代码中处理
其他信息:从SA_Buildings&#39;中获取价值时出错on&#39; System.Data.Entity.DynamicProxies.SA_Locations_720FF8784B152496318F87BCB674E344B97C0446B16D4DC2BDDC381D88C048B9&#39;。
所以,它确实指向了与SA_Locations有关的东西,正如我所说,它是由实体框架数据库首先生成的类....
越来越近但不知道为什么该对象不会序列化?
答案 0 :(得分:0)