R Siva
R Siva

Reputation: 11

ASP.NET Boilerplate: Unable to hit the service from index.js

We are trying to implement a custom service using .NET Core Multi Page Application template. We are receiving an error in index.js file when trying to hit a service method.

Find herewith the code sections for understanding. Any help on this will be really helpful for us.

public interface IMyTaskAppService : IApplicationService
{
    Task<List<string>> GetMyTasks(int input);
}

public class MyTaskAppService : IMyTaskAppService
{
    private readonly IMyTaskRepository _mytaskRepository;

    public MyTaskAppService(IMyTaskRepository mytaskRepository)
    {
        _mytaskRepository = mytaskRepository;
    }

    Task<List<string>> IMyTaskAppService.GetMyTasks(int input)
    {
        return _mytaskRepository.GetMyTasks(input);
    }

}

Error Screenshot 1

Error Screenshot 2

Index.Js

Index.Js Error (Lowercase)

Console Output Screenshot

Upvotes: 1

Views: 1170

Answers (2)

Alper Ebicoglu
Alper Ebicoglu

Reputation: 9634

Add ApplicationService as a base for your MyTaskAppService class. See my code;

public class MyTaskAppService : ApplicationService, IMyTaskAppService
{
    private readonly IMyTaskRepository _mytaskRepository;

    public MyTaskAppService(IMyTaskRepository mytaskRepository)
    {
        _mytaskRepository = mytaskRepository;
    }

    Task<List<string>> IMyTaskAppService.GetMyTasks(int input)
    {
        return _mytaskRepository.GetMyTasks(input);
    }    
}

See TaskAppService.

public interface IMyTaskAppService : IApplicationService
{
    Task<List<string>> GetMyTasks(int input);
}

See the complete source-code of SimpleTaskSystem

Upvotes: 0

aaron
aaron

Reputation: 43098

  1. MyTaskAppService requires at least one public method:

    public class MyTaskAppService : IMyTaskAppService
    {
        // ...
    
        // Task<List<string>> IMyTaskAppService.GetMyTasks(int input)
        public Task<List<string>> GetMyTasks(int input)
        {
            return null;
        }
    }
    

    What you have is an explicit implementation that is "more restricted than private".

  2. Service and method names are in camelCase for Client Proxies.

    Use an uppercase T for myTask:

    var _myTaskService = abp.services.app.myTask;
    

    Use a lowercase g for getMyTasks:

    _myTaskService.getMyTasks({
        taskID: taskID
    }).done(function (data) {
        alert(data);
    });
    

Upvotes: 1

Related Questions