以下代码在IIS Express中正常工作,但在IIS10中失败。
奇怪的是可以成功调用服务器端方法,但客户端方法不能。
var hub = $.connection.liveRoomHub;
hub.client.addMessageToPage = function(data){
debugger;//here, this method never gets invoked
console.log(JSON.stringify(data));
};
$.connection.hub.start()
.done(function() {
hub.server.join('room1')
.done(function(){
debugger; //code can run into here
hub.server.sendMessage('user','test','room1');
})
});
public class LiveRoomHub : Microsoft.AspNet.SignalR.Hub
{
public ILogger Logger { get; set; }
public async Task SendMessage(string name, string message, string roomName)
{
await Clients.Group(roomName)
.addMessageToPage(new
{
Name = name,
Message = message
});
Logger.Info($"{name}send msg:{message}in room:{roomName},");//logged
}
public async Task Join(string roomName)
{
await Groups.Add(Context.ConnectionId, roomName);
Logger.Info($"{Context.ConnectionId} enter room: {roomName}");//logged
}
}
答案 0 :(得分:4)
好的,问题解决了。
我正在使用aspnetboilerplate,abp.signalr.js
会在加载JavaScript代码之前自动调用集线器连接。
显然,当时我的hub.client.addMessageToPage
尚未注册。
这是常见的Connection started before subscriptions are added
错误。