I have a ASP.NET application. I run it by hitting debug. It runs on localhost:2842.
I have a SignalR Hub defined in a class with no methods on the server.
I have a WPF Windows C# application. I added the SignalR NuGet package. I use the following code to instantiate the client proxy:
var hubConnection = new HubConnection("http://localhost:2842");
IHubProxy myHubProxy = hubConnection.CreateHubProxy("MyHub");
myHubProxy.On<string>("SendMeData", dataString => {
Console.WriteLine("String value {0}", dataString);
});
hubConnection.Start().Wait();
Here is my hub class defined on the server:
public class MyHub : Hub
{
public static void SendMeData(string dataString)
{
var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
if (context != null)
context.Clients.All.SendMeData(dataString);
}
}
I have this code in Startup.cs:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
app.MapSignalR(new HubConfiguration
{
EnableDetailedErrors = true
});
}
}
The problem I am having is that when the C# client calls hubConnection.Start().Wait(); I get a very unhelpful exception. Here is the exception:
StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content:
System.Net.Http.StreamContent, Headers: Transfer-Encoding: chunked
X-SourceFiles: =?UTF-8?B?QzpcTXlEZXZcUmVhbHRpbWVNRFxSZWFsdGltZU1EUHJvdG9cUmVhbHRpbWVNRFByb3RvXHNpZ25hbHJcbmVnb3RpYXRl?=
Cache-Control: private Date: Thu, 27 Apr 2017 04:23:18 GMT Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Type: text/html; charset=utf-8
I set break points in the server code and it never hits any of them.
How do I figure this out?
The whole problem ended up being that I had changed the name of my Hub class in the server without changing the name used in CreateHubProxy. it is working now.