SignalR demo not working

I follow this quick guide to starting a SignalR project, and in my Hub class I have the following

using Microsoft.AspNet.SignalR.Hubs; namespace MvcApplication8.Hubs { public class ChatHub : Hub { public void BroadcastMessage(string message) { Clients.writeMessage(message); } } } 

Client Code:

  $(document).ready(function () { var chat = $.connection.chatHub; chat.writeMessage = function(msg) { $("#messages").append("<li>" + msg + "</li>"); }; $("#buttonSubmit").click(function () { chat.broadcastMessage($("#txtInput").val()); }); $.connection.hub.start(); }); 

However, I get a compilation error:

'Microsoft.AspNet.SignalR.Hubs.HubConnectionContext' does not contain the definition of 'writeMessage' and the extension method 'writeMessage' Accepting the first argument of the type "Microsoft.AspNet.SignalR.Hubs.HubConnectionContext" can be found (you are missing the using directive or assembly references ?)

Where did it go wrong?

I installed SignalR into my project from http://nuget.org/packages/microsoft.aspnet.signalr using the "Install-Package Microsoft.AspNet.SignalR -Pre" package manager console

+7
source share
4 answers

Follow this guide:

https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs

It will always be relevant and correct. Unlike many blog posts.

+5
source

Is an appropriate client function created?

 <script type="text/javascript"> $(function () { var chat = $.connection.chat; chat.writeMessage = function (message) { $('#messages').append('<li>' + message + '</li>'); }; $.connection.hub.start(); }); </script> 
+1
source

Check if the following packages are installed:

  • Microsoft.AspNet.SignalR
  • Microsoft.AspNet.SignalR.Core
  • Microsoft.AspNet.SignalR.Hosting.AspNet
  • Microsoft.AspNet.SignalR.Hosting.Common
+1
source

Try updating NuGet packages. TOOLS> NuGet Package Manager> Managing NuGet packages for the solution, click "Updates" in the left part of the window, in the center of the windows you will get a list of packages that need to be updated, then click "Install" above the package that you like to get the latest version. I am updating everything: jQuery, Json.NET, Microsoft ASP.NET SignalR, Microsoft.Owin

After updating the packages to the latest version (SignalR Currently 2.2.0) you can compile. Do not forget the update links in "StockTicker.html", in my case after the update it looks like this:

 <script src="/Scripts/jquery-2.1.4.min.js"></script> <script src="/Scripts/jquery.signalR-2.2.0.js"></script> 
0
source

All Articles