【发布时间】:2015-07-22 23:39:48
【问题描述】:
我有一个带有 webClient 和 webAPI 的单页应用程序。当我转到一个有表格的视图时,我的表格没有被更新。实际上,该 API 仅在应用程序启动时被调用一次,即使假设每次都会调用它,或者我预期会发生什么。
服务代码-
function getPagedResource(baseResource, pageIndex, pageSize) {
var resource = baseResource;
resource += (arguments.length == 3) ? buildPagingUri(pageIndex, pageSize) : '';
return $http.get(serviceBase + resource).then(function (response) {
var accounts = response.data;
extendAccounts(accounts);
return {
totalRecords: parseInt(response.headers('X-InlineCount')),
results: accounts
};
});
}
factory.getAccountsSummary = function (pageIndex, pageSize) {
return getPagedResource('getAccounts', pageIndex, pageSize);
};
API 控制器 -
[Route("getAccounts")]
[EnableQuery]
public HttpResponseMessage GetAccounts()
{
int totalRecords;
var accountsSummary = AccountRepository.GetAllAccounts(out totalRecords);
HttpContext.Current.Response.Headers.Add("X-InlineCount", totalRecords.ToString());
return Request.CreateResponse(HttpStatusCode.OK, accountsSummary);
}
我可以将它追踪到服务,但它不会在控制器中遇到断点。
【问题讨论】:
-
你确定你的后续调用不是简单地被缓存,因此在第一次请求后永远不会命中控制器吗?尝试在控制器端添加these set of response headers,看看有没有效果。
-
factory.getAccountsSummary函数何时被调用? -
factory.getAccountsSummary 在控制器的 Init() 上被调用。
标签: angularjs rest asp.net-web-api