Пример #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            client.BaseAddress = new Uri("https://localhost:44313/api/values/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            while (!stoppingToken.IsCancellationRequested)
            {
                var urlParams = DateTimeOffset.Now.Second;
                HttpResponseMessage response = client.GetAsync(urlParams.ToString()).Result;
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                if (response.IsSuccessStatusCode)
                {
                    var object1 = response.Content.ReadAsStringAsync(stoppingToken).Result.Trim('"');
                    _logger.LogInformation("Web service via rest api        : {0}", object1);
                }
                else
                {
                    _logger.LogError("The website is down");
                }
                var object2 = await wcfClient.GetDataAsync(urlParams);

                _logger.LogInformation("Web service directly            : {0}", object2);

                var object3 = wcfEmployeeClient.Run();
                _logger.LogInformation("Employee Web service directly   : {0}", object3);
                _logger.LogInformation("*******************************");
                await Task.Delay(5000, stoppingToken);
            }
        }