我已经安装了Web-Api路由调试器,试图弄清楚这里发生了什么,它报告了以下异常: -
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=Multiple actions were found that match the request:
System.Net.Http.HttpResponseMessage GetTasksByParentAndList(Int32, Int32, Int32, Int32) on type AcademicStudio.WebHost.Controllers.TasksController
System.Net.Http.HttpResponseMessage GetTasksByListTreeAndDepartmentAndTerms(Int32, Int32, Int32, Int32, Int32[], Int32[]) on type AcademicStudio.WebHost.Controllers.TasksController
Source=System.Web.Http
StackTrace:
at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)
at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)
at AcademicServer.WebHost.Areas.RouteDebugger.InspectActionSelector.SelectAction(HttpControllerContext controllerContext) in d:\AcademicServer\AcademicServer.WebHost\Areas\RouteDebugger\InspectActionSelector.cs:line 42
at System.Web.Http.Tracing.Tracers.HttpActionSelectorTracer.<>c__DisplayClass2.<System.Web.Http.Controllers.IHttpActionSelector.SelectAction>b__0()
at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)
InnerException:
这两个动作都在控制器中使用ActionName属性声明,如下所示:(并且具有不同的参数)。
[ActionName("ParentAndList")]
public HttpResponseMessage GetTasksByParentAndList(Int32 parentId, Int32 listId, Int32 fromId, Int32 toId)
{
var service = new TaskService();
var data = service.SelectTasksByParentAndList(parentId, listId, fromId, toId);
return Request.CreateResponse(HttpStatusCode.OK, data);
}
[ActionName("ListTreeAndDepartmentAndTerms")]
public HttpResponseMessage GetTasksByListTreeAndDepartmentAndTerms(Int32 parentId, Int32 listId, Int32 fromId, Int32 toId, [FromUri]Int32[] defs, [FromUri]Int32[] depts)
{
var service = new TaskService();
var data = service.SelectTasksByListTreeAndDepartmentAndTerms(parentId, listId, fromId, toId, defs, depts);
return Request.CreateResponse(HttpStatusCode.OK, data);
}
有谁可以解释发生了什么?控制器包含许多使用ActionName声明的其他操作,它们工作正常。
更新
发布问题十分钟后我发现了:在WebApiConfig.cs中没有正确配置MapHttpRoutes
为什么你可以在放弃后十分钟盯着某些东西,然后放弃一分钱,最后放下一个问题呢?