ASP.NET 样板 WebAPI 方法
本文关键字:方法 WebAPI 样板 NET ASP | 更新日期: 2023-09-27 18:37:21
我正在尝试在 ASP.NET 样板上工作我的项目。
我现在正在创建动态 Web API,这是我所拥有的:
我的应用服务:
public interface IBorrowLendAppService : IApplicationService
{
GetBorrowLendsOutput GetBorrowLends(GetBorrowLendsInput input);
}
我的输入:
public class GetBorrowLendsInput : IInputDto
{
public byte ItemType { get; set; }
public int PersonId { get; set; }
}
这是我的问题:
- 如何调用此方法?
- 如何创建 GET/POST 方法(样板文档中没有关于它的信息)
当我调用一个方法 [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
}
当我尝试像这样调用它时:
.../GetBorrowLends?项目类型=0&人员 ID =1
我收到同样的错误
使用数据调用 [POST]:
{
"input":{
"ItemType":"0",
"PersonId":"1"
}
}
返回另一个错误:
{
"result": null,
"success": false,
"error": {
"code": 0,
"message": "An internal error occured during your request!",
"details": null,
"validationErrors": null
},
"unAuthorizedRequest": false
}
我该如何处理?以及如何手动创建 GET/POST 方法?
谢谢
编辑:
我已经处理了无法正常工作的端点问题。我在开机自检消息中错误地设置了"内容类型"参数。
但是关于ApplicationService中的GET/POST方法的问题仍然悬而未决。
默认的 HttpVerb 设置为 Post。
/// <summary>
/// Default HTTP verb if not set.
/// </summary>
private const HttpVerb DefaultVerb = HttpVerb.Post;
然后IApiControllerActionBuilder
有一个方法来改变动作的动词。
IApiControllerActionBuilder<T> WithVerb(HttpVerb verb);
您应该能够通过以下调用(Initialize
WebAPI 模块)更改谓词
DynamicApiControllerBuilder
.For<ITaskAppService>("tasksystem/taskService")
.ForMethod("SomeMethod").WithVerb(HttpVerb.Get)
.Build();
更多信息可在网站上获得。