private bool StartConnectionToHub() { if (HubConnectionIsAlreadyConnected()) { return(false); } //add retry policy to get access token var tokenContent = accessTokenService.GetToken(); var accessToken = accessTokenService.ExtractAccessToken(tokenContent); accessTokenExpiryDate = accessTokenService.ExtractAccessTokenExpiryDate(tokenContent); var queryString = new Dictionary <string, string> { { "bearer_token", HttpUtility.UrlEncode(accessToken) } }; var hubUrl = "http://localhost:8093"; hubConnection = new HubConnection(hubUrl, queryString) { TraceLevel = TraceLevels.All, TraceWriter = new Log4NetTextWriter(new MessagingLogger()), DeadlockErrorTimeout = TimeSpan.FromMinutes(5) }; RegisterHubConnectionEvents(); hubProxy = hubConnection.CreateHubProxy <IBackOfficeHub, IBackOfficeHubClient>(HubName); //subscribe before connection is started so that you can make your replay all messages call // inside the connection event SetUpHubConnectionSubscriptions(); hubConnection.Start(new ServerSentEventsTransport()).Wait(); return(true); }