2

I have a weird problem with Web API where I am using the same naming convention for my restful service except I have an Multiple actions were found that match the request with one method but not with the other. I'll show an example so my problem can be understood:

#region SKILL LEVEL
[HttpGet]
[Route("EducationCourseSkillLevel/{id}")]
public HttpResponseMessage GetSkillLevel(int id)
{
    var result = _service.RetrieveEducationCourseSkillLevel(id);
    return GetResponse(result);
}

[HttpGet]
[Route("EducationCourseSkillLevel")]
public HttpResponseMessage GetSkillLevels()
{
     var result = _service.RetrieveEducationCourseSkillLevels();
     return GetResponse(result);
 }
 #endregion

If I use a tool like Postman I can call both of these methods and data is returned.

#region BOOKING SOURCE
[HttpGet]
[Route("EducationCourseBookingSource/{id}")]
public HttpResponseMessage GetBookingSource(int id)
{
    var result = _service.RetrieveEducationCourseBookingSource(id);
    return GetResponse(result);
}

[HttpGet]
[Route("EducationCourseBookingSource")]
public HttpResponseMessage GetBookingSources()
{
    var result = _service.RetrieveEducationCourseBookingSources();
    return GetResponse(result);
}

#endregion

EducationCourseBookingSource without the ID doesn't work. It thinks there are multiple actions.

{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nEducationCourseBookingSource on type RHS.CRM.Application.Areas.Course.CourseController\r\nGetBookingSources on type RHS.CRM.Application.Areas.Course.CourseController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.Tracing.Tracers.HttpActionSelectorTracer.<>c__DisplayClass2.b__0()\r\n 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)\r\n at System.Web.Http.Tracing.Tracers.HttpActionSelectorTracer.System.Web.Http.Controllers.IHttpActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Tracing.Tracers.HttpControllerTracer.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.Tracing.ITraceWriterExtensions.d__18`1.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

Does anyone know what the problem could be?

Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
nick gowdy
  • 6,191
  • 25
  • 88
  • 157
  • Similar topic is discussed here: http://stackoverflow.com/questions/14534167/multiple-actions-were-found-that-match-the-request-webapi – JGV Jul 24 '15 at 03:32

0 Answers0