我有一个ASP.NET SignalR项目版本2.4。 我在Signalr服务器上创建了一个Hub(使用webapp) 然后像这样重写Onconnected方法:
public override Task OnConnected()
{
_log.Debug("OnConnected: " + Context.ConnectionId);
Interlocked.Increment(ref _usersCount);
var user = new UserDataDto()
{
ConnectionId = Context.ConnectionId,
ClientId = Context.QueryString["clientId"],
GroupName = Context.QueryString["groupName"],
Token = Context.QueryString["access_token"],
RefreshId = Context.QueryString["refresh_token"],
MachineId = Context.QueryString["machineId"],
SystemName = Context.QueryString["systemName"],
ConnectedAt = DateTime.Now
};
_users[Context.ConnectionId] = user;
_log.Debug("AddGroup: AddGroup");
AddGroup(Context.ConnectionId, Context.QueryString["systemName"], Context.QueryString["groupName"], Context.QueryString["machineId"], Context.QueryString["clientId"]);
return base.OnConnected();
}
集线器客户端:
var connection = $.hubConnection(PUlSE_SETTINGS.signalUri);
me.signalR.logging = true;
connection.qs = {
'server': false,
'access_token': sessionFactory.get('access_token'),
'refresh_token': sessionFactory.get('refresh_token'),
'clientId': sessionFactory.get('clientId'),
'groupName': me.groupName,
'systemName': me.systemName,
'machineId': '',
'role': sessionFactory.get('role')
};
var chatHub = connection.createHubProxy(PUlSE_SETTINGS.hubName);
connection.start().done(function () {
console.log(chatHub.connection.state);
});
当客户端连接时,连接成功启动(console.log显示状态1),但是对OnConnected方法没有任何动作。因此,我们无法接收到从信号服务器发送的任何数据:
Clients.All.SendMessage(machineId, json);
对此问题有何建议?