0
votes

I am getting the following error when query a recursive entity lookup.

Error:

{"message":"An error has occurred.","exceptionMessage":"There is an action GetCategories defined for api controller app/category but with a different HTTP Verb. Request verb is GET. It should be Post","exceptionType":"System.Web.HttpException","stackTrace":" at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.GetActionDescriptorByActionName(HttpControllerContext controllerContext, DynamicApiControllerInfo controllerInfo, String actionName)\r\n at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.DynamicApiController1Proxy_5.ExecuteAsync_callback(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.Invocations.ApiController_ExecuteAsync_5.InvokeMethodOnTarget()\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Abp.WebApi.Controllers.Dynamic.Interceptors.AbpDynamicApiControllerInterceptor1.Intercept(IInvocation invocation)\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Castle.Proxies.DynamicApiController`1Proxy_5.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

The error only occurs after I added the first entry that has a ParentId

Model

     [Table("Categories")]
     public class Category : FullAuditedEntity
     {
        [Required]
        public string Name { get; set; }
        [Required]
        public string SharepointMapping { get; set; }
        public int? ParentId { get; set; }
        public Category Parent { get; set; }
       public List<Category> Children { get; set; }
     }

CategoryAppService

  public ListResultDto<CategoryListDto> GetCategories(GetCategoriesInput input)
  {
    var categories = _categoryRepository
        .GetAll()
        .WhereIf(
            !input.Filter.IsNullOrEmpty(),
            p => p.Name.Contains(input.Filter) 
        )
        .OrderBy(p => p.Name)
        .ToList();

        return new ListResultDto<CategoryListDto>(categories.MapTo<List<CategoryListDto>>());
  }

CategoryListDto

[AutoMapFrom(typeof(Category))]
public class CategoryListDto : FullAuditedEntityDto
{
    public string Name { get; set; }
    public string SharepointMapping { get; set; }
    public int? ParentId { get; set; }
    public virtual Category Parent { get; set; }       
}
1

1 Answers

1
votes

The default http-verb for all WebApi methods is POST. Make your request with POST.


If you don't like this solution, you can use conventional verbs. With Conventional verbs, it looks the method name prefix and matches the related http-verb.

  • GetCategories -> HTTP-GET
  • DeleteCategory -> HTTP-DELETE
  • UpdateCategory -> HTTP-PUT
  • CreateCategory -> HTTP-POST

you can use WithConventionalVerbs method as shown below:

Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
    .ForAll<IApplicationService>(Assembly.GetAssembly(typeof(SimpleTaskSystemApplicationModule)), "tasksystem")
    .WithConventionalVerbs()
    .Build();

For further information: https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API