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
I changed the code like below and I started to work.
app.MapSignalR<ConnectionHub>("/echo");
ConnectionHub is the class that inherit from PersistentConnection. The examples on the internet does not require to specify the class but they didnt work for me.
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<MyAwesomeConnection>("/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:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<script type="text/javascript" src="Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.signalR-2.1.1.min.js"></script>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<script>
var connection = $.connection("/server", "testQuery=This crap finally works", true);
connection.start();
</script>
@RenderBody()
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
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.