Visual studio android emulator cannot connect to my local pc's asp.net web api

YoussefAzaroualiYoussefAzarouali USMember ✭✭

I have a web api running on iis on my pc. I start the visual studio 2015 android emulator and I want to reach the api through the browser on the emulator. It doesn't work and it gives me a time out.

When I go to other websites it works fine, so there is nothing wrong with the network switch setting (I guess). I tried the following things to get it working:
- I've checked the firewall settings the world wide webservices is switched on for inbound rules.

  • I have tried to reinstall the emulator also nothing works.
  • I typed the IP (http://192.168.135.145/myapi) on the browser of the computer it works fine. - I also turned off the firewall and tried it but with no succes.
  • I heve checked the virtual switch on the hyperv, it exists.

Am I missing something? It worked before but after updating windows, it doesn't.

I hope somebody can help me out.

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭

    You should be able to access localhost from an android emulator with this IP address here: 10.0.2.2

    It works slightly different when using an android emulator. Find out more information here:
    https://developer.android.com/studio/run/emulator-networking

  • YoussefAzaroualiYoussefAzarouali USMember ✭✭

    Hi Seanyda, thank you very much for your answer. I am using the visual studio emulator for android (via hyperv)? And I also tried the to type http://10.0.2.2/myapi in the browser of the emulator. But still no succes.

    Am I doing something else wrong?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @YoussefAzarouali said:
    Hi Seanyda, thank you very much for your answer. I am using the visual studio emulator for android (via hyperv)? And I also tried the to type http://10.0.2.2/myapi in the browser of the emulator. But still no succes.

    Am I doing something else wrong?

    Sorry if its not localhost on your machine and you're using your local address to access it, You might need this address instead 10.0.2.1

    Check the documentation I sent you, It has all the info there.

  • YoussefAzaroualiYoussefAzarouali USMember ✭✭

    @seanyda said:

    @YoussefAzarouali said:
    Hi Seanyda, thank you very much for your answer. I am using the visual studio emulator for android (via hyperv)? And I also tried the to type http://10.0.2.2/myapi in the browser of the emulator. But still no succes.

    Am I doing something else wrong?

    Sorry if its not localhost on your machine and you're using your local address to access it, You might need this address instead 10.0.2.1

    Check the documentation I sent you, It has all the info there.

    Thanks for the info. I checked out the documentation, but isn't it for the android emulator of android studio it self? I'm new to this. Before this happened it worked fine with my local ip address, how come that it doesn't support it anymore? I'm using hyper v visual studio androi emulator. Can you please explain to me step by step what to do?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @YoussefAzarouali said:

    @seanyda said:

    @YoussefAzarouali said:
    Hi Seanyda, thank you very much for your answer. I am using the visual studio emulator for android (via hyperv)? And I also tried the to type http://10.0.2.2/myapi in the browser of the emulator. But still no succes.

    Am I doing something else wrong?

    Sorry if its not localhost on your machine and you're using your local address to access it, You might need this address instead 10.0.2.1

    Check the documentation I sent you, It has all the info there.

    Thanks for the info. I checked out the documentation, but isn't it for the android emulator of android studio it self? I'm new to this. Before this happened it worked fine with my local ip address, how come that it doesn't support it anymore? I'm using hyper v visual studio androi emulator. Can you please explain to me step by step what to do?

    Is 10.0.2.1 not working? Android emulators are android emulators, regardless of the dev environment. I don't think there is any special configuration, You just need to access your local router IP and local host IP with different IP addresses.

  • YoussefAzaroualiYoussefAzarouali USMember ✭✭

    Hi seanyda, I just deleted hyperv and then added it again, and afterwards it worked like charm. That's weird, because I didn't do anything special.

    Thank you very much for your effort to help me.

  • JohnHJohnH GBMember ✭✭✭✭✭

    I have a similar setup to you for iOS and Android development with IIS on my laptop. I just use the machine name for the laptop in the URLs used by the app, so the app calls http://mylaptopnetworkname/mytestwebapicall when I am developing. But to be fair I use real hardware, not emulators.

  • The same issue I was getting when I work on Adobe Photoshop. Trying to connect to the router for the network but It cant be resolved. I just reached this site to get a solution to my query routertechnicalsupportnumbers.com/linksys-router-support because I am using WRT1900AC AC190 and I am to close to get it but not done. Can you please share any other information to get the full details.

  • YoussefAzaroualiYoussefAzarouali USMember ✭✭

    Sorry no more details. The only thing that worked for me whas reinstalling the hyperv. What I also noticed is that when I connect my pc to multipul wifi networks, the emulator doesn't always get a connection with your local network.

Sign In or Register to comment.