I installed SignalR 2.0.2 to my MVC 4.5 Application by using package manager console. And I did the standard example for the connection configuration.
names
Ok, the solution Ryu provided is correct - but might be confusing to many. To be honest, I haven't found a single walkthrough (used exact same code as examples) - but nothing has worked, partly due to the fact that a lot of stuff becomes obsolete as the signalr-project advances.
So, you have a class which extends PersistentConnection, and inside this class you have all the Tasks (OnConnected, OnReceived etc):
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
public class MyAwesomeConnection : PersistentConnection
{
protected override Task OnConnected(IRequest request, string connectionId)
{
var fromClient = request.QueryString["testQuery"];
return base.OnConnected(request, connectionId);
}
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
return base.OnReceived(request, connectionId, data);
}
}
And then you "map" that class (in this case MyAwesomeConnection) in the OwinStartup class:
using DataCommunication;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(SignalRServer.Startup))]
namespace SignalRServer
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR("/server");
}
}
}
Now you can connect with javascript, and be very careful when referencing the jquery and jquery.signalR scripts. jquery first, jquery.signalR second, then all of your other scripts which utilize the signalR stuff and avoid the @Scripts.Render("bundles/jquery"). Just do it the old fashion way:
@ViewBag.Title
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@RenderBody()
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
Set a breakpoint somewhere inside OnConnected in the MyAwesomeConnection class, and read out the variable fromClient, which will fire once the client (javascript) connects. It should hopefully read out "this crap finally works".
Now you should be good to go with building something spectacular with signalR, if something still doesn't work - then you are either missing some assemblies from nuget or references not set correctly in the project.