public async Task <(bool resultado, AutorModeloRemote autor, string ErrorMessage)> GetAutor(Guid AutorId) { try { HttpClient cliente = _httpClient.CreateClient("AutorService"); HttpResponseMessage response = await cliente.GetAsync($"/Autor/Autor?id={AutorId}"); if (response.IsSuccessStatusCode) { string contenido = await response.Content.ReadAsStringAsync(); JsonSerializerOptions options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; AutorModeloRemote resultado = JsonSerializer.Deserialize <AutorModeloRemote>(contenido, options); return(true, resultado, null); } return(false, null, response.ReasonPhrase); } catch (Exception e) { _logger.LogError(e.ToString()); return(false, null, e.Message); } throw new NotImplementedException(); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { Stopwatch tiempo = Stopwatch.StartNew(); _logger.LogInformation("Inicia el request"); HttpResponseMessage response = await base.SendAsync(request, cancellationToken); if (response.IsSuccessStatusCode) { string contenido = await response.Content.ReadAsStringAsync(); JsonSerializerOptions options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; LibroModeloRemote resultado = JsonSerializer.Deserialize <LibroModeloRemote>(contenido, options); var responseAutor = await _autorRemote.GetAutor(resultado.AutorLibro ?? Guid.Empty); if (responseAutor.resultado) { AutorModeloRemote objetoAutor = responseAutor.autor; resultado.AutorData = objetoAutor; string resultadoStr = JsonSerializer.Serialize(resultado); response.Content = new StringContent(resultadoStr, System.Text.Encoding.UTF8, "application/json"); } } _logger.LogInformation($"Estre proceso se hizo en {tiempo.ElapsedMilliseconds}ms"); return(response); }