Hi @Holysmokes-6260 ,
Could you please share the MagentoClientService related codes and how you call the MagentoClientService? I have created a test demo and it works well on my side.
Below is my test demo codes:
Client service:
public class CountryRepositoryClientV2 : ICountryRepositoryClient
{
private readonly HttpClient _client;
private readonly ILogger<CountryRepositoryClientV2> _logger;
public CountryRepositoryClientV2(HttpClient client, ILogger<CountryRepositoryClientV2> logger)
{
_client = client;
_logger = logger;
}
public async Task<string> GetAsync()
{
using (HttpResponseMessage response = await _client.GetAsync("/api/democrud"))
{
try
{
return await response.Content.ReadAsStringAsync();
}
catch (Exception e)
{
_logger.LogError(e, "Failed to read content");
return null;
}
}
}
}
Startup.cs:
services.AddHttpClient<ICountryRepositoryClient, CountryRepositoryClientV2>()
.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://localhost"))
.AddHttpMessageHandler((services) =>
{
return new TraceLogHandler(services.GetRequiredService<IHttpContextAccessor>(),
services.GetRequiredService<ILogger<TraceLogHandler>>());
});
I used it inside the home controller:
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IHttpContextAccessor ihttpcontextaccessor;
private readonly ICountryRepositoryClient countryRepositoryClient;
public HomeController(ILogger<HomeController> logger, IHttpContextAccessor _ihttpcontextaccessor, ICountryRepositoryClient _countryRepositoryClient)
{
_logger = logger;
_ihttpcontextaccessor = ihttpcontextaccessor;
countryRepositoryClient = _countryRepositoryClient;
}
public async Task<IActionResult> IndexAsync()
{
await countryRepositoryClient.GetAsync();
//HttpContext.Session.SetString("IsLogin", "true");
return View(new PatientModel { statusOfPatient=1 });
}
Result:
You could find the breakpoint has been fired:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.