private bool PostAcknowledgment(SendAcknowledgementCommand sendAcknowledgementCommand) { var token = accessTokenService.GetToken(); var accessToken = accessTokenService.ExtractAccessToken(token); //add a retry policy here using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken); var auditApiAcknowledgementControllerUrl = "http://localhost:8094/api/Acknowledgement"; using ( var httpResponse = httpClient.PostAsJsonAsync(new Uri(auditApiAcknowledgementControllerUrl), sendAcknowledgementCommand) .Result) { return(httpResponse.IsSuccessStatusCode); } } }
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); }