C# ASP.NET样板WebApi方法

C# ASP.NET样板WebApi方法,c#,asp.net,asp.net-web-api,boilerplate,C#,Asp.net,Asp.net Web Api,Boilerplate,我正试图在ASP.NET样板上开始我的项目 我现在正在创建动态Web API,下面是我所拥有的: 我的应用程序服务: public interface IBorrowLendAppService : IApplicationService { GetBorrowLendsOutput GetBorrowLends(GetBorrowLendsInput input); } 我的意见: public class GetBorrowLendsInput : IInputDto {

我正试图在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?ItemType=0&PersonId=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方法

谢谢

编辑:

我已经处理了端点不工作的问题。我在POST消息中错误地设置了“内容类型”参数


但关于ApplicationService中的GET/POST方法的问题仍然存在。

默认的HttpVerb设置为POST

/// <summary>
/// Default HTTP verb if not set.
/// </summary>
private const HttpVerb DefaultVerb = HttpVerb.Post;
您应该能够通过以下调用更改谓词(在WebAPI模块的
Initialize
中)

DynamicCapicontrollerBuilder
.For(“任务系统/任务服务”)
.ForMethod(“somethod”).WithVerb(HttpVerb.Get)
.Build();

可以获得更多信息。

看起来您需要确保正确定义了路线。看起来它们是正确的。执行不同的路由会产生一个错误,即它不知道路由。您可以发布您希望在请求中调用的方法的控制器代码吗?您可能还应该包括路由。我已经处理了请求的问题,但请求不起作用。这是POST中的“内容类型”参数。我的工具将其设置为“text”,应该是“application/json”。但我仍然对POST/GET方法有疑问
IApiControllerActionBuilder<T> WithVerb(HttpVerb verb);
DynamicApiControllerBuilder
    .For<ITaskAppService>("tasksystem/taskService")
    .ForMethod("SomeMethod").WithVerb(HttpVerb.Get)
    .Build();