SignalR does not call seconf Hub class
I have 2 Hub classes in my project
public class FolderManager : Hub
{
public FolderManager()
{
}
public void Validator()
{
}
}
public class SeoContentValidator : Hub
{
public SeoContentValidator()
{
}
public void Validator()
{
}
}
I have an elementary class
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
In my opinion I have this script
<script src="~/Scripts/jquery.signalR-2.2.0.js" type="text/javascript"></script>
<script src="~/signalr/hubs" type="text/javascript"></script>
<script>
jQuery(document).ready(function(){
var folderManager = $.connection.folderManager;
var seoContentValidator = $.connection.seoContentValidator;
$.connection.hub.logging = true;
$.connection.hub.start().done(function () {
folderManager.server.validator();
seoContentValidator.server.validator();
});
});
</script>
The problem I am facing is signalR can find and call folderManager.server.validator ();
But cant find seoContentValidator.server.validator ();
What am I doing wrong in SeoContentValidator that signalR cannot find it
source to share
This should work fine. Actually, I tried an example for you. My signalr / hubs proxy generator has the following code:
proxies['folderManager'] = this.createHubProxy('folderManager');
proxies['folderManager'].client = { };
proxies['folderManager'].server = {
validator: function () {
return proxies['folderManager'].invoke.apply(proxies['folderManager'], $.merge(["Validator"], $.makeArray(arguments)));
}
};
proxies['seoContentValidator'] = this.createHubProxy('seoContentValidator');
proxies['seoContentValidator'].client = { };
proxies['seoContentValidator'].server = {
validator: function () {
return proxies['seoContentValidator'].invoke.apply(proxies['seoContentValidator'], $.merge(["Validator"], $.makeArray(arguments)));
}
};
And when running, my js log says:
[ ... ] SignalR: Invoking foldermanager.Validator
[ ... ] SignalR: Invoking seocontentvalidator.Validator
I also set breakpoints on the hub methods and ran the application in debug mode. Both breakpoints are triggered.
Is the JS code that I copied is present in your generated proxy file? Don't have any JS errors on startup?
I am assuming that the example code you wrote is not your actual code. Try to debug the code, also use detailed error messages:
public class Startup {
public void Configuration(IAppBuilder app) {
var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
app.MapSignalR(hubConfiguration);
}
}
Wrap your hub methods in try-catch blocks, it can help a lot.
Let me know if you find a problem.
source to share