【发布时间】:2015-10-07 02:06:06
【问题描述】:
我让 SignalR 与 Angular 客户端一起工作,但如果在我订阅事件之前建立了连接,我无法让 proxy.on() 工作。
我的服务器方法在两个集线器上调用客户端方法pushToClient。
var connection1 = $.hubConnection(); //Works fine since I started connection AFTER subscribing
var proxy1 = connection1.createHubProxy('clientPushHub');
proxy1.on('sendToClient', function (message) {
console.log('This will work: ' + message);
});
connection.start();
var connection2 = $.hubConnection(); // Doesn't work when I start the connection BEFORE subscribing
var proxy2 = connection2.createHubProxy('clientPushHub');
connection2.start();
proxy2.on('sendToClient', function (message) {
console.log('This will not work: ' + message);
});
如果我在启动 connection2 之前更改了一些设置,以便 proxy2 订阅 pushToClient,它可以正常工作。还尝试在 start().done() 回调中进行“on”订阅,但没有成功。
我已经下载并验证了this example 在订阅后 连接时按预期工作,this ASP.NET article/section 特别提到如果您不使用生成的代理,您可以按此顺序执行操作,我没有。
this SO question 中对提问者有效的方法对我无效。
有什么我可能出错的想法吗?
【问题讨论】:
标签: signalr