Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR .NET Client: Cannot Start Connection From Within Web Application App Domain

Tags:

signalr

I'll try to make a long story short:

I want to call a method on a hub in a web application from a core assembly in my application. Reason being is that I have a number of applications that all eventually call into core and trigger events (think mobile web, admin site, api, etc). I want to notify users of the desktop site of events as they happen, using SignalR.

To spike this, I created a 4-project solution. A core project with the hub proxy. A web app with the hub. Another web app without the hub. And finally a console app.

If I call into core from the console app, and try to send a message to hub clients using the proxy, everything works great. However, if I try to call into core and use the proxy from one of the web apps, the execution hangs at the call to connection.Start():

var connection = new HubConnection("...");
var hub = connection.CreateProxy("Spike.Hub");
connection.Start().Wait();

Is the SignalR.Client stuff not meant to be used from within a web app's app domain? Why does it work as expected in the console app, but not from a web app?


Update: I hooked my spike into the SignalR source and when running from one of the web apps, execution hangs at line 130 of SignalR.Client.Connection. The _syncContext for such a connection is an instance of AspNetSynchronizationContext, and when calling its Post() method, everything stops.

like image 333
spot Avatar asked Mar 02 '12 22:03

spot


1 Answers

There's a bug in the SignalR.Client and you found it :)

like image 79
davidfowl Avatar answered Oct 26 '22 21:10

davidfowl