Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Emulator loopback to IIS Express does not work, but does work with Cassini

I am attempting to post data from an Android application running in the Android Emulator on my local machine to a web application running under IIS Express also running on my local machine. Unfortunately, when I post to 10.0.2.2 from the emulator I receive a Host Not Found error message.

If I configure the web application to run under ASP.NET Dev Server (Cassini) instead of IIS Express the Android application is able to post with no problems. What configuration am I missing for IIS Express that is preventing it from working with a loopback from the Android emulator?

like image 336
ahsteele Avatar asked May 31 '11 19:05

ahsteele


People also ask

How do I connect IIS Express to an Android emulator?

Grant yourself permission to bind to network adapters other than localhost, and configure IIS express to bind to all adapters. IIS Express will then accept connections from the Android emulator via 10.0.2.2.

What is the loopback interface address of the emulator?

Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you want to access services running on your development machine loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.

Why is my Android application returning 400 error in IIS Express?

The request from Android does not have “localhost” as Host header (guess what’s value then?), so it would be dropped, and a 400 error is returned. You might wonder if we can get rid of the error by modifying IIS Express configuration file.

How to connect genymotion emulator to IIS Express?

For Genymotion emulator, need to add <binding protocol="http" bindingInformation="*:8085:192.168.56.1" /> and run web service on the same ip address and port no. Then only my emulator is connecting to my iis express (port no can be replaced with desired one). By default, IIS Express only accepts connections from localhost.


2 Answers

Grant yourself permission to bind to network adapters other than localhost, and configure IIS express to bind to all adapters.

IIS Express will then accept connections from the Android emulator via 10.0.2.2. If you add a rule to the firewall, you can also expose IIS Express to your network, which decreases security but is useful for testing physical devices.

Step details: (they assume a port number of 5555 - use your actual port instead)

  1. Run this from a command prompt as Administrator:

    netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"

  2. In %USERPROFILE%\Documents\IISExpress\config\applicationhost.config, replace your site's localhost binding with bindingInformation="*:5555:*". The result should look like this:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>
like image 73
Edward Brey Avatar answered Nov 13 '22 12:11

Edward Brey


Add following line to IIs config file (ex c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config ) Change the port 8085 if required..

<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />

so your config file will end-up with something like this

<bindings>
<binding protocol="http" bindingInformation="*:4396:localhost" />     // the existing one
<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />     // new line
</bindings>

now you can call your web service from remote by calling to port 8085

ex from android emu.
new HttpPost("http://10.0.2.2:8085");
like image 33
kuma DK Avatar answered Nov 13 '22 11:11

kuma DK