Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Convert the Application Project post method to GET. #4919


User avatar
0
OriAssurant created

I have a kendoui grid in .Web project and App/ folder as index.cshtml

From index.js when I attempt to make a call to the web api. (Web API which was automatically created by ASP Net Zero after implementing DI)

The service is called CartService and below is the method I am trying to access:

    public PagedResultDto<ShoppingCartListDto> GetCartData()
    {
  }

The error I am getting is :

{"message":"An error has occurred.","exceptionMessage":"There is an action GetCartData defined for api controller app/shoppingCartService 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_3.ExecuteAsync_callback(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.Invocations.ApiController_ExecuteAsync_3.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_3.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.

I understand that the problem here is to specify the method as GET. But, how do I do that in ASP NET Zero class?


4 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    Hi,

    You can use HttpGet attribute on the application service method.

    public interface ITaskAppService : IApplicationService
    {
        [HttpGet]
        GetTasksOutput GetTasks(GetTasksInput input);
    
        [HttpPut]
        void UpdateTask(UpdateTaskInput input);
    
        [HttpPost]
        void CreateTask(CreateTaskInput input);
    }
    

    See <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API#http-attributes">https://aspnetboilerplate.com/Pages/Doc ... attributes</a>

  • User Avatar
    0
    OriAssurant created

    Yes, I had tried that. But still shows up as POST method in Swagger

  • User Avatar
    0
    alper created
    Support Team

    Try Naming Convention feature.

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

    <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API#naming-convention">https://aspnetboilerplate.com/Pages/Doc ... convention</a>

  • User Avatar
    0
    OriAssurant created

    Thank you!