[英]ASP.NET Boilerplate WebApi methods
I'm trying to get to work my project on ASP.NET Boilerplate. 我正试图在ASP.NET Boilerplate上开始我的项目。
I'm right now creating Dynamic Web API and here is what I have: 我现在正在创建动态Web API,这就是我所拥有的:
My AppService: 我的AppService:
public interface IBorrowLendAppService : IApplicationService
{
GetBorrowLendsOutput GetBorrowLends(GetBorrowLendsInput input);
}
My Input: 我的意见:
public class GetBorrowLendsInput : IInputDto
{
public byte ItemType { get; set; }
public int PersonId { get; set; }
}
And here's my problem: 这是我的问题:
When I'm invoking a method [GET]GetBorrowLends without any data I'm receiving error: 当我在没有任何数据的情况下调用方法[GET] GetBorrowLends时,我收到错误:
{
"result": null,
"success": false,
"error": {
"code": 0,
"message": "Your request is not valid!",
"details": null,
"validationErrors": [
{
"message": "input is null!",
"members": [
"input"
]
}
]
},
"unAuthorizedRequest": false
}
When I'm trying to invoke it like: 当我试图调用它时:
.../GetBorrowLends?ItemType=0&PersonId=1 ... / GetBorrowLends?的ItemType = 0&PERSONID = 1
I'm receiving same error 我收到同样的错误
Invoking [POST] with data: 使用数据调用[POST]:
{
"input":{
"ItemType":"0",
"PersonId":"1"
}
}
Returning another error: 返回另一个错误:
{
"result": null,
"success": false,
"error": {
"code": 0,
"message": "An internal error occured during your request!",
"details": null,
"validationErrors": null
},
"unAuthorizedRequest": false
}
How do I handle that? 我该如何处理? And how to create GET/POST methods manually? 以及如何手动创建GET / POST方法?
Thanks 谢谢
Edit: 编辑:
I have handled problem with not working endpoint. 我处理了不工作端点的问题。 I have wrongly set 'Content-Type' parameter in POST message. 我错误地在POST消息中设置了'Content-Type'参数。
But question about GET/POST methods in ApplicationService is still open. 但是关于ApplicationService中的GET / POST方法的问题仍然存在。
The default HttpVerb is set to Post. 默认的HttpVerb设置为Post。
/// <summary>
/// Default HTTP verb if not set.
/// </summary>
private const HttpVerb DefaultVerb = HttpVerb.Post;
Then there is a method in IApiControllerActionBuilder
to change the verb of an action. 然后在IApiControllerActionBuilder
有一个方法来更改动作的动词。
IApiControllerActionBuilder<T> WithVerb(HttpVerb verb);
You should be able to change the verb with the following call (in Initialize
of your WebAPI module) 您应该可以使用以下调用更改动词(在WebAPI模块的Initialize
中)
DynamicApiControllerBuilder
.For<ITaskAppService>("tasksystem/taskService")
.ForMethod("SomeMethod").WithVerb(HttpVerb.Get)
.Build();
Further information could be obtained on the website . 可以在网站上获得更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.