0
keepfool created
I am trying the SimpleTaskSystem, when I use ajax get to get all tasks, I got an error: Your request is not valid! Here is the steps I have done.
- Download the source code of SimpleTaskSystem from github.
- Restore referenced packages through Nuget.
- Change the ITaskApplicationService
public interface ITaskAppService : IApplicationService
{
[HttpGet]
GetTasksOutput GetTasks(GetTasksInput input);
[HttpPut]
void UpdateTask(UpdateTaskInput input);
[HttpPost]
void CreateTask(CreateTaskInput input);
}
- I want to show all the tasks by http get method, the rerequest uri is <a class="postlink" href="http://localhost:6247/api/services/tasksystem/task/GetTasks">http://localhost:6247/api/services/task ... k/GetTasks</a>. Then I got this error at the home page: Your request is not valid! But if I change the ITaskApplicationService as below, I can successfully get the tasks.
public interface ITaskAppService : IApplicationService
{
[HttpPost]
GetTasksOutput GetTasks(GetTasksInput input);
[HttpPut]
void UpdateTask(UpdateTaskInput input);
[HttpPost]
void CreateTask(CreateTaskInput input);
}
How can I get tasks with http get?
1 Answer(s)
-
0
This is related to working of ASP.NET Web API.
Get only supports primitive parameters by default, not complex types (like GetTasksInput). To make it work, you can change method signature like:
[HttpGet] GetTasksOutput GetTasks([FromUri] GetTasksInput input);
See <a class="postlink" href="http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api">http://www.asp.net/web-api/overview/for ... et-web-api</a> for more