1

我有以下集线器类:

public class Dashboard : Hub, IDisconnect, IConnected
    {
        //Initialize Repoisotries 
        private IProfileRepository profileRepository;
        private ISiteDataRepository siteDataRepository;
        private readonly IHubContext matchContext = GlobalHost.ConnectionManager.GetHubContext<MatchMaker>();

    //Constructor Injection for profile repository and site data repository
    public Dashboard(IProfileRepository repo, ISiteDataRepository siteRepo)
    {            
        profileRepository = repo;
        siteDataRepository = siteRepo;            
    }
    public Task Disconnect()
    {
        return null;
    }
    public Task Reconnect(IEnumerable<string> connections)
    {
        return null;
    }
    public Task Connect()
    {
        Debug.WriteLine(MatchMaker.onlineUsers.Count);
        return null;
    }
    public void GetUserInfo()
    {
        Debug.WriteLine(MatchMaker.onlineUsers.Count);
    }
}

}

我的信号器包括:

<script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>

我像这样访问它:

$(function () {
    //Create the proxy
    var Dashboard = $.connection.dashboard;
    $.connection.hub.start(function () {
        Dashboard.getUserInfo();

    });
});

当我调用Dashboard.getUserInfo()该方法时,该方法被称为 find,但该Connect()方法一开始就不会触发。

4

1 回答 1

1

我发现出了什么问题......只要我添加了这样的方法:

$(function () {
//Create the proxy
var Dashboard = $.connection.dashboard;

Dashboard.someMethod = function(message){
}

$.connection.hub.start(function () {
    Dashboard.getUserInfo();

});
});

我的Connect()功能开始触发,不知道您需要一个客户端功能来激活连接。

于 2012-08-09T22:09:48.737 回答