3

I have a SignalR hub setup like this:

public sealed class NotificationUserHub : Hub {

    private ILogger Logger { get; }

    private IUserConnectionManager UserConnectionManager { get; }

    public NotificationUserHub(IUserConnectionManager userConnectionManager, ILoggerFactory logFactory) {
        UserConnectionManager = userConnectionManager ?? throw new ArgumentNullException(nameof(userConnectionManager));
        Logger = logFactory.CreateLogger<NotificationUserHub>();
    }

    public async Task<string> GetConnectionIdAsync() {
        HttpContext httpContext = Context.GetHttpContext();
        StringValues userId = httpContext.Request.Query["userId"];
        StringValues resourceId = httpContext.Request.Query["resourceId"];
        Logger.LogInformation($"Received connection request for user {userId} and resource {resourceId}");
        await UserConnectionManager.KeepUserConnectionAsync(userId, 
            Context.ConnectionId, resourceId).ConfigureAwait(false);
        return Context.ConnectionId;
    }

    public async override Task OnDisconnectedAsync(Exception exception) {
        string connectionId = Context.ConnectionId;
        await UserConnectionManager.RemoveUserConnectionAsync(connectionId).ConfigureAwait(false);
    }
}

I'm trying to test that this works in Postman. The client is able to connect but none of the requests are being received on the server. My guess is that there's a specific message structure required to interface with the hub but I can't find any documentation on it. What is the structure of the payload I should use to call GetConnectionIdAsync in my hub?

Update:

I attempted to implement it using this and I was, again, able to connect and authenticate with the server. However, I was unable to call the function, even after encoding my message in the format described here.

Woody1193
  • 7,252
  • 5
  • 40
  • 90
  • 1
    Maybe this will help: https://github.com/dotnet/AspNetCore.Docs/issues/6431 – Evk Oct 20 '21 at 15:20
  • 1
    This question has been asked and answered at https://stackoverflow.com/questions/68231360/how-to-invoke-a-signalr-core-hub-method-from-postman-websocket – Brennan Oct 20 '21 at 15:24
  • @Brennan Looks like it was actually answered at https://stackoverflow.com/questions/68094092/how-to-invoke-a-signalr-core-hub-method-from-postman-websocket-king. Still, I appreciate the feedback so I'll close this question. – Woody1193 Oct 21 '21 at 01:02
  • @Brennan I just noticed that your answer on that question has not been accepted. I'll close this question when that one has an accepted answer. – Woody1193 Oct 23 '21 at 03:03
  • 3
    Does this answer your question? [How to invoke a SignalR Core hub method from Postman WebSocket](https://stackoverflow.com/questions/68231360/how-to-invoke-a-signalr-core-hub-method-from-postman-websocket) – Adrian Dec 27 '21 at 16:43

0 Answers0