【发布时间】:2015-01-13 22:13:56
【问题描述】:
我正在尝试在 ASP.NET Boilerplate 上开展我的项目。
我现在正在创建动态 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 消息中错误地设置了“Content-Type”参数。
但是关于 ApplicationService 中的 GET/POST 方法的问题仍然悬而未决。
【问题讨论】:
-
看起来您需要确保您的路线定义正确。
-
似乎是。执行不同的路由会给出一个未知路由的错误
-
您能否发布您希望通过请求调用的方法的控制器代码?您可能还应该包括路由。
-
我已经处理了请求不起作用的问题。它是 POST 中的“Content-Type”参数。我的工具将其设置为“文本”,应该是“应用程序/json”。但我对 POST/GET 方法仍有疑问
标签: c# asp.net asp.net-web-api boilerplate