I'm having a problem with the following methods:
[Authorize]
[HttpGet]
[ResponseType(typeof(IEnumerable<Index.Model>))]
public async Task<IHttpActionResult> GetArchives()
[Authorize]
[HttpGet]
[ResponseType(typeof(Get.Query))]
public async Task<IHttpActionResult> GetArchive(Get.Query query)
It is giving me the following error:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Multiple actions were found that match the request: GetArchives on type IAP.api.Controllers.ArchivesController GetArchive on type IAP.api.Controllers.ArchivesController
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace>
at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext) at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext) at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
</StackTrace>
</Error>
I've read through the other solutions for people asking the same question, but haven't worked for me (more specifically this one). I'm looking for a solution where I don't need to change my Web Api default REST routing as I will have to change it in the client also.
Thanks,
It's actually problem with same routings. You can try to use Route
attribute to change the route for one of these methods but not the whole routing scheme. Also with these attribute you can try to not change route name (GetArchives) but use additional route constraint for your second method. And then it will be something like this:
/archives/GetArchives
/archives/GetArchives/GetQueryConstraint
To achieve this place [Route("{query}")]
on the second method. If this is your custom object then you will need to create your custom constraint and specify it
[Route("{query:constraintType}")]