【发布时间】:2014-12-16 13:12:11
【问题描述】:
我的 angularclient 能够调用 serverhub。但永远不会收到来自服务器的推送消息,使用此行发送:hub.Clients.All.serverTime(DateTime.UtcNow.ToString());
出于调试目的,我在订阅 (signalrhubproxy.js) 中添加了 console.log(...):
proxy.on(eventName, function (result) {
console.log('event:' + eventName + ' received.' ); <--- never fired
$rootScope.$apply(function () {
if (callback) {
callback(result);
}
});
});
我已经按照本教程 Pushing Data: Integrating with ASP.NET SignalR Hubs 进行了一些操作 我的应用中的修改:
-
它有一个带有 startup.cs 的 WebAPI 结构,具有以下 SignalR 配置:
app.Map("/signalr", map => { map.UseCors(CorsOptions.AllowAll); var hubConfiguration = new HubConfiguration { EnableDetailedErrors = true, EnableJSONP = true }; map.RunSignalR(hubConfiguration); });而不是在 global.asax 中:
RouteTable.Routes.MapHubs(新的 HubConfiguration { EnableCrossDomain = true });
AreaRegistration.RegisterAllAreas(); WebAPI 在 localhost:2034 (VS) 上运行
- 客户端运行在 localhost:9000 (grunt)
我能够:
- 从客户端调用服务器方法getServerTime。
- 运行BackgroundServerTimeTimer
- 在BackgroundServerTimeTimer 中获取hub:
hub = GlobalHost.ConnectionManager.GetHubContext<ClientPushHub>();
并通知客户:
hub.Clients.All.serverTime(DateTime.UtcNow.ToString()); <--- no error serverside, no glory clientside
这是我的盒子吗?
- 我的盒子在 Windows 7 上运行并且有 VS 2013
更新 我已经实现了简单的'Getting started chatsample',而没有更改服务器配置。这很有效。所以,很明显这是我的 angularjs 中的客户端问题。
【问题讨论】:
标签: c# angularjs asp.net-web-api signalr