0

I have this two methods which both of them are GET methods without parameters:

[HttpGet]
    [ActionName("ProductsTypes")]
    public dynamic ProductsTypes()
    {
        DbConnection.Connect();
        var result = DbConnection.GetProductsTypes();
        DbConnection.Disconnect();
        return result;
    }

    [HttpGet]
    [ActionName("ProductsInfo")]
    public dynamic ProductsInfo()
    {
        DbConnection.Connect();
        var result = DbConnection.GetProductsInfo();
        DbConnection.Disconnect();
        return result;
    }

and i defined the routes to be:

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { action="get", id = RouteParameter.Optional }
        );

the url for each one of the methods is:

http://localhost:14775/api/shekem/ProductsInfo for the ProductsInfo method
http://localhost:14775/api/shekem/ProductsTypes for the ProductsTypes method

however, i keep getting this error:

{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nProductsTypes on type ShekemService.Controllers.ShekemController\r\nProductsInfo on type ShekemService.Controllers.ShekemController","ExceptionType":"System.InvalidOperationException","StackTrace":"   at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
kitsuneFox
  • 1,243
  • 3
  • 18
  • 31

0 Answers0