I am trying to connect a WCF service hosted at my local IIS express from an Android app. Currently, I am testing this on an Emulator.
Local URL for the service is http://locahost:40000/api/Authenticate
I knew that localhost is not going to work and I used 10.0.2.2 in the code
post = new HttpPost("http://10.0.2.2:40000/api/authenticate");
but the response on client execute is an "Invalid Hostname"
I tried editing the ApplicationHost.config of IIS express and added a binding entry for 10.0.2.2 but that didn't work too
Is there anything else that I am missing ?
As I understand it, 10.0.2.2 is an alias for 127.0.0.1, so add that to your applicationhost.config
binding for your site, e.g.
<site name="MySite" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="{yourpath}" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:26013:localhost" />
<binding protocol="http" bindingInformation="*:26013:127.0.0.1" />
</bindings>
</site>
Bear in mind that these days if you're using Visual Studio the relevant applicationhost.config
for your site may not be in c:\users\...
but rather in a .vs\config
folder at the root of your solution.
I tried something else which worked , I added the IP address of my system within the IIS Express applicationhost.config file bindings sections.
<bindings>
<binding protocol="http" bindingInformation="*:40000:localhost" />
<binding protocol="http" bindingInformation="*:40000:192.168.5.118" />
</bindings>
I am able to call the service now
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With