2016-12-22 17 views
3

Я пытаюсь вывести кэш в моем Webapi. Я установил пакет Nuget« Strathweb.CacheOutput.WebApi2 »в соответствии с обсуждением . в статье ниже https://github.com/filipw/Strathweb.CacheOutput После установки я использовал:Ошибка 500 «Запросы не могут быть применены к контенту ответа типа« System.Net.Http.ByteArrayContent »

[CacheOutput(ClientTimeSpan = 100, ServerTimeSpan = 100, AnonymousOnly = true)] 
    public HttpResponseMessage Get() 
    { 
     var list = context.Colors.ToList(); 
     return Request.CreateResponse(HttpStatusCode.OK,list.AsQueryable<Color>()); 
    } 

возвращает эту ошибку:..

{"Message":"An error has occurred.","ExceptionMessage":"Queries can not be applied to a response content of type 'System.Net.Http.ByteArrayContent'. The response content must be an ObjectContent.\r\nParameter name: actionExecutedContext","ExceptionType":"System.ArgumentException","StackTrace":" at System.Web.Http.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

Что я могу сделать, чтобы решить эту проблему, я новичок с Web Api Благодаря

ответ

3

Поскольку Web Api - последний шаг в серверной цепочке, IQueryable необходимо выполнить/оценить перед отправкой с ответом. Таким образом, простое решение просто отправляет список, поскольку это

public HttpResponseMessage Get() 
{ 
    var list = context.Colors.ToList(); 
    return Request.CreateResponse(HttpStatusCode.OK,list); 
}