【发布时间】:2014-11-21 10:23:50
【问题描述】:
我正在开发一个 Web 服务,其中我拥有类型 A 的资源拥有类型 B 的资源。
我想开发一个 API 来获取关于 A 的统计信息,但只考虑其 B 的子集。
所以我有一条路线,采用 A 的 ID,B 的 ID 集合,并返回统计信息。我会像下面这样使用它:
POST /api/StatsAboutA/{aId}
JSON payload:
[1, 4, 12]
它会返回类似的东西:
[
{"key": ..., "value": ...},
...
]
这是我的控制器:
class StatsAboutAController : ApiController
{
// ...
// POST api/StatsAboutA/{aId}
[HttpPost]
public Stats Post(long aId, IEnumerable<long> bIds)
{
A a = _aRepository.SelectById(aId);
if (a == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return _aRepository.CollectStats(a, bIds);
}
// ...
}
我无法配置我的路由器以使我的控制器匹配我的路由。
这是我收到的错误消息:
{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:51398/api/StatsAboutA/1'.",
"messageDetail": "No action was found on the controller 'StatsAboutA' that matches the request."
}
【问题讨论】: