I have created a ASP.NET Web Application (.Net Framework) in VS2017, I have selected an Empty project and ticked the Web API checkbox. I don't want MVC. I install from Nuget Microsoft.AspNet.SignalR. All is well. Then I
Add an OWIN Startup class and add the line app.MapSignalR(); in the Configuration method.
using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(WebApplication4.Startup))] namespace WebApplication4 { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } }I create a Hub called MyTestHub with a single method Activate.
using Microsoft.AspNet.SignalR; namespace WebApplication4 { public class MyTestHub : Hub { public string Activate() { return "Monitor Activated"; } } }I create an html page to test with the following:
<script src="Scripts/jquery-1.6.4.min.js"></script> <script src="Scripts/jquery.signalR-2.2.2.js"></script> <script src="signalr/hubs" type="text/javascript"></script> <script type="text/javascript"> $(function () { var notificationHub = $.connection.myTestHub; $.connection.hub.start(function () { notificationHub.activate(function (response) { console.log("response", response); }); }); }); </script>
The hub is created, $.connection.hub.start is fine, but notificationHub.activate returns "Object doesn't support property or method 'activate'". I cannot find the function on notificationHub but I do find it on notificationHub.server. However, calling notificationHub.server.activate does nothing.
I have tried the latest stable version of SingnalR and 2.2.2 (as the sample project) but nothing works. signalr/hibs is OK.
Any ideas? All the examples I have seen basically do this, but I cannot get it to work.