如何调用web Api返回对象列表

时间:2016-08-28 11:28:22

标签: asp.net-web-api

我试图调用web Api返回一个对象列表,但它总是抛出一个错误:内部服务器错误

我的代码如下: Web API

// GET: api/UploadFileStructures
        [ResponseType(typeof( IEnumerable<UploadFileStructure>))]
        public IHttpActionResult GetUploadFileStructuresByMovieId(int MovieDetailId)
        {
            IEnumerable<UploadFileStructure> uploaFileStructures= db.UploadFileStructures.Where(u=>u.MovieDetailId== MovieDetailId).AsEnumerable();
            return Ok(uploaFileStructures);
        }

Http请求:

  using (var client = new HttpClient(handler))
            {
                //client.BaseAddress = UsersLogin;
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));            

     var response = client.GetAsync(String.Format(GetUploadFileStructuresByMovieIdUrl, MovieDetailId)).Result;
            if (response.IsSuccessStatusCode)
            {

                UploadFileStructureDtls= response.Content.ReadAsAsync<IQueryable<UploadFileStructure>>().Result;

            }
        }

response.IsSuccessStatusCode正在返回false并返回响应&#34;内部服务器错误&#34;

1 个答案:

答案 0 :(得分:0)

问题出在服务器代码的这一行:

IEnumerable<UploadFileStructure> uploaFileStructures= db.UploadFileStructures.Where(u=>u.MovieDetailId== MovieDetailId).AsEnumerable();

如果在那里设置断点,您应该能够看到生成的实际错误消息。