SignalR behandelt nicht die empfangene Hub -AufklärungC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 SignalR behandelt nicht die empfangene Hub -Aufklärung

Post by Anonymous »

Ich habe SignalR Hub mit mehreren Endpunkten, alle Endpunkte außer einer.

Code: Select all

//I set additional parameters to Logging configuration in application.json
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.SignalR": "Debug",//this
"Microsoft.AspNetCore.Http.Connections": "Debug"//and this one
}
}
< /code>
Protokolliert, wenn Client Endpoint Verbraucher aufruft:
dbug: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[1] Received hub invocation: InvocationMessage { InvocationId: "2", Target: "ConsumeCandidate", Arguments: [ lolkek, 581dc267-d2ff-403f-924c-cd6dba40535b ], StreamIds: [  ] }.

Server hat keine Probleme mit der Empfangsnachricht, aber Hub ruft keine erforderliche Methode auf.

Code: Select all

public class LobbyHub(ILobbyService lobbyService, ILogger logger, IGameService gameService,
IElectionManager electionManager) : Hub
{
// this method should be invoked
public void ConsumeCandidate(string lobbyName, string userClientId)
{
logger.LogInformation($"Chancellor candidate received from: {userClientId}");
}

//For instance hub is able to invoke this one
public async Task StartGame(string lobbyName, string userClientId)
{
await gameService.StartRound(lobbyName, userClientId);
}
}

app.MapHub("/lobbyhub");
Wie Sie sehen, kann es keine Namensprobleme sein. Beachten Sie auch, dass alle anderen Methoden dieses Hubs gut funktionieren, die Verbindung nicht verloren geht, derselbe Client kann nach dem Verbraucherung andere Endpunkte aufrufen, und damit sind keine Probleme. Es gibt keine Protokolle von der Verbraucher -Verbraucher - -Methode, wenn die Nachricht vom Client empfangen wird. Ich habe versucht, die Methode der Verbraucherrecandidate zu debuggen, aber aufgrund dessen kann Debuggen nicht geholfen. Ich kann nur sagen, dass der Server eine Nachricht empfängt, aber sie nicht verarbeitet.

Code: Select all

builder.Services.AddSignalR().AddHubOptions(options =>
{
options.EnableDetailedErrors = true;
});
< /code>
Clientcode: < /p>
const invokeMethod = async (methodName, ...args) => {
console.log("Invoking method:", methodName, "\nwith args:", args);
console.log("Connection state:", connection.state);
return connection.invoke(methodName, ...args);
};

function setChoosingCandidatesButton(candidates) {
candidates.allCandidates.forEach((candidate) => {
const candidateButton = document.getElementById('s' + candidate.index);
candidateButton.textContent = "choose";
candidateButton.dataset.id = candidate.userId + " " + candidates.lobbyName;
candidateButton.onclick = (e) => {
let data = e.target.dataset.id.split(" ");
invokeMethod("ConsumeCandidate", data[1], data[0]);
};
});
}

Ich habe den zweiten Hub hinzugefügt, um die Methode zu testen:

Code: Select all

public class GameHub(ILogger logger,
IElectionManager electionManager) : Hub
{
public async Task ConsumeCandidate(string lobbyName, string userClientId)
{
logger.LogInformation($"Chancellor candidate received from: {userClientId}");
}
}
< /code>
Protokolle: < /p>
dbug: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[1]
Received hub invocation: InvocationMessage { InvocationId: "0", Target: "ConsumeCandidate", Arguments: [ lolkek, 581dc267-d2ff-403f-924c-cd6dba40535b ], StreamIds: [  ] }.
info: SecretHitler.WebApp.Hubs.GameHub[0]
Chancellor candidate received from: 581dc267-d2ff-403f-924c-cd6dba40535b

Überschreibt auch OndisconNectedaSync

Code: Select all

//This method from LobbyHub
public override Task OnDisconnectedAsync(Exception? exception)
{
logger.LogInformation($"Client disconnected {Context.ConnectionId}");
return base.OnDisconnectedAsync(exception);
}
Es gibt keine Ausnahmen oder Protokolle von OndisconnectedaSync .

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post