I am experiencing some issues with configuring my project to use SignalR. The connection gets established from my Client to the Hub, and I can see my logs in Seq indicating that the messages are being sent, but I am not receiving any messages in the Client. I have struggled with this for a long time, and I am not sure what exactly I have done wrong?
I have my Hub class:
public class SourceControlHub : Hub
{
}
In Startup I add signalR service:
services.AddSignalR();
And map the hub:
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health");
endpoints.MapSwagger();
endpoints.MapControllers();
endpoints.MapHub<SourceControlHub>("/sourceControlHub");
});
I send my message like this:
await _hub.Clients.All.SendAsync("SendProgressReportMessage", snapshotId, uploadCount, uploaded);
I connect to the hub connection like this:
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';
import * as signalR from '@microsoft/signalr';
@Injectable({
providedIn: 'root'
})
export class SignalRService {
SIGNALR_URL = environment.signalRBaseUrl;
public hubConnection: signalR.HubConnection;
public startConnection = () => {
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(this.SIGNALR_URL + '/sourceControlHub')
.build();
this.hubConnection
.start()
.then(() => console.log('Connection started'))
.catch(err => console.log('Error while starting connection: ', err));
};
public addProgressReportingListener() {
this.hubConnection.on(
'SendProgressReportMessage',
(snapshotId, toUpload, uploaded) => {
console.log(
'reporting the data: ' +
snapshotId +
' ' +
uploaded +
' of ' +
toUpload
);
}
);
}
}
And initiate it in my component:
this.signalRService.startConnection();
this.signalRService.addProgressReportingListener();
I tried with an older version of @aspnet/signalr which didn't work either. I am currently using latest version of @microsoft/signalr in the Angular project.
Edit: Moved the last paragraph, where I explained the issue, to the top of the post.
question from:
https://stackoverflow.com/questions/65953127/net-core-3-1-and-angular-6-signalr-setup-connects-but-not-receiving-messages 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…