. net maui app | .net web api | Tool - Visual stdio | Database - Sql server

Connection failed error in runtime.

Step 1 : I'm creating api its worked fine. I'm double checked through the postman & swagger. Step 2 : I'm creating maui app through the visual stdio 2022 and consuming both api and maui app and run it in window's machine its worked fine

Step 3 : I'm creating android emulator and run it through the application in android emulator. Its was not worked properly i don't know why?

(Note) I'm not using entity framework.

While run in the window's machine is worked But, While run on android emulator showing connection failed

builder.Services.AddDemoApiClientService(x => x.ApiBaseAddress = "https://localhost:7107"); builder.Services.AddDemoApiClientService(x => x.ApiBaseAddress = "https://192.168.1.138:7107");

Try : Endpoint config change

Expecting : Through the android emulator also i need to work properly.(Api with maui app)

1

There are 1 best solutions below

3
mpasdanis On

The correct address to use when trying to access your local development server from an Android emulator is 10.0.2.2 .

In the context of Android emulators, 10.0.2.2 is a special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine). This means that when your app running on the Android emulator tries to connect to 10.0.2.2, it is actually attempting to connect to the localhost of the machine running the emulator.

For instance, if you have a Web API running on your development machine accessible at http://localhost:7107, you can access it from your app running inside the Android emulator by using the URL http://10.0.2.2:7107.