2
votes

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>");
        }
    }
}
1
Make sure localhost:8087 is up and running and you have configured it on startup (in case of .NET core web API) - CodeConstruct
it up and running 100% sure and i am not using .net core just .net 5 - user2698555
An HTTP 500 error means that something went wrong on the server - likely an exception. If you wrote the server side, then debug the server side and find the exception. - Gabriel Luci

1 Answers

1
votes

Without the exception detials I can only guess.

Maybe "chekroomstauts" is a typo and your server wants to call "checkroomstatus"?

Maybe "Join" is not defined?

Kind regards Bernd