I am trying to make SignalR Client work from C# code but I couldn't. I got this error:
"StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
Access-Control-Allow-Origin: *
Cache-Control: private
Date: Tue, 30 Jul 2019 11:54:07 GMT
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: text/html; charset=utf-8
}"
But it works fine from jQuery. This is my code:
I tried this tutorial : https://programmer.group/signalr-hubs-api-details-net-c-client.html and also at the server side this my startup file code
var config = new HubConfiguration();
config.EnableDetailedErrors = true;
config.EnableJSONP = true;
app.MapSignalR(config);
And this in the Client side:
async void ConnectToSignlr()
{
try
{
HubConnection hubConnection = new HubConnection("http://localhost:8087/");
hubConnection.Credentials = System.Net.CredentialCache.DefaultCredentials;
hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;
IHubProxy proxy = hubConnection.CreateHubProxy("ChatHub");
proxy.On<string>("chekroomstauts", (message) =>
{
//do something on your ui maybe?
Response.Write("hello you connected");
});
proxy.On("notify", (message) =>
{
Response.Write("hello you notify");
}
);
// connect to hup pro
await hubConnection.Start();
await proxy.Invoke("Join", "1000");
}
catch (AggregateException ex)
{
foreach (var errInner in ex.InnerExceptions)
{
//Debug.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary
Response.Write(errInner + "</br>");
}
}
}