Android device fails to connect to local host API through WiFi (.NET Maui app.)

Will 0 Reputation points
2023-10-26T13:29:05.06+00:00

For some reason I can no longer connect to my local .NET Core web API when testing on my Android phone (plugged in via USB).

Nothing has changed in my code, however there were 3 Windows 10 updates done, but I could not see anything in the updates that impacted the httpClient call.

I also added a windows inbound firewall rule for that port #, available on domain, private and public. I even allowed all inbounds for each entity, to no avail.

It works when I bring up a browser, also works on the android phone browser which means the phone can see the API, but only when I run the app via the phone httpClient fails to connect. Also tried it via the emulator using 10.0.0.2 with no issues.

I'm following MS recommended standard when using httpClient.

IPv4 local machine: 10.X.X.XX

10.X.X.XX Injected into my service layer .NET MAU code - Maui program.cs

builder.Services.AddHttpClient<ITestService, TestService>(client =>
{
client.BaseAddress = new Uri("http://10.X.X.XX:xxxx/");
});

Test Service class
private readonly HttpClient _httpClient;
JsonSerializerOptions _serializerOptions;

public TestService(HttpClient httpClient)
{
_httpClient = httpClient;

_serializerOptions = new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    WriteIndented = true
};
}

Method Get
HttpResponseMessage response = await _httpClient.GetAsync(_httpClient.BaseAddress + "api/Test/Get/");

API - launch settings file
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://10.X.X.XX:xxxx",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},

I'm lost at this point because I feel I have everything in order, but obviously not, seems like a firewall issue but I do have the inbound rule on TCP specific for that port #, not sure what I'm missing here.

Using VS 2022 17.7.6 Samsung S10

Edition Windows 10 Pro Version 22H2 OS build 19045.3570 Experience Windows Feature Experience Pack 1000.19052.1000.0

All devices are currently updated.

Any help is much appreciated.

Thanks

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,166 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,870 questions
{count} votes