【发布时间】:2017-12-13 09:34:41
【问题描述】:
执行以下 Web api 方法时出现运行时错误
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
web api 控制器
[Route("api/movies")]
public IHttpActionResult Get()
{
var movies = _movieBusiness.GetAllMovies();
return Ok(movies);
}
业务逻辑方法
public List<Movie> GetAllMovies()
{
var movies = _movieRepository.GetMovies();
_unitOfWork.Dispose();
return movies;
}
数据访问方式
public List<Movie> GetMovies()
{
var query = "dbo.spGetMovies";
var list = SqlMapper.Query<Movie>(_unitOfWork.GetConnection(), query, commandType: CommandType.StoredProcedure);
return list;
}
【问题讨论】:
-
是否存在内部异常,提供有关对象序列化失败原因的更多详细信息?
-
将内容复制到流时出错。
标签: asp.net-web-api