C# ApiController返回504-服务器未对此请求返回完整响应。服务器返回了0字节
我给我的ApiController打了一个电话,它返回了一个504,我只是不知道我做错了什么 有人能看到我的问题吗 这是控制器:C# ApiController返回504-服务器未对此请求返回完整响应。服务器返回了0字节,c#,asp.net-apicontroller,C#,Asp.net Apicontroller,我给我的ApiController打了一个电话,它返回了一个504,我只是不知道我做错了什么 有人能看到我的问题吗 这是控制器: public class SA_GetAllLocationsController : ApiController { [Route("SA_GetAllLocations")] [HttpGet] public List<SA_Locations> Get() { List<SA_
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_位置返回时似乎没有错误,但我在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_GetAllLocationsController:ApicController
{
[路线(“SA_GetAllLocations”)]
[HttpGet]
公共HttpResponseMessage Get()
{
列表结果=SADatastore.Functions.Location.GetAllLocations(Settings.Default.ConnectionString);
字符串输出=JsonConvert.SerializeObject(结果);
返回新的HttpResponseMessage()
{
内容=新内容(
产出,
Encoding.UTF8,
“应用程序/json”
)
};
}
}
它现在实际上抛出了一个错误,将SA_Locations对象序列化为字符串
错误消息是:
Newtonsoft.Json.Json.JsonSerializationException类型的异常在Newtonsoft.Json.dll中发生,但未在用户代码中处理
其他信息:从“System.Data.Entity.DynamicProxies.SA_Locations_720FF8784B152496318F87BCB674E344B97C0446B16D4DC2BDCC381D88C048B9”上的“SA_Buildings”获取值时出错
所以,它确实指向与SA_位置有关的东西,正如我所说的,SA_位置是由实体框架数据库首先生成的一个类
越来越近,但不知道为什么该对象不会序列化?这一切归结为配置。ProxyCreationEnabled=false 嗯
public HttpResponseMessage Get()
{
return new HttpResponseMessage()
{
Content = new StringContent(
"SA service is running and ready to accept connections!",
Encoding.UTF8,
"text/html"
)
};
}
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"
)
};
}
}