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.