Forum Xamarin.Android

Accessing localhost on device and emulator

astahirastahir USMember ✭✭

Hello there,

I worked on an app a couple of years ago and now I have to make enhancements to it. As it was my first (and only so far!) project so I had problem accessing web service on device as well as emulator at the beginning. However, I finally managed to run on emulator when I asked the following question on this forum:

Now the problem is that when I tried running the same code, it does not access localhost through emulator. I never managed to run it on device even earlier and now too. I was using for emulator. Here are the points on which I would like your help please:

1) Why am I not able to run the same exact code to get to localhost? I can access the web service when I open it in my laptop's browser like http://localhost:16299/MainService/PerformAnAction?str1=test. As I already said the code is exactly the same, one difference is that I previously worked on Windows 7 and now it's Windows 8. Is there any setting to be modified? I tried applying few things which I found on the net but I either get Request TimeOut or Error: ConnectFailure (Connection timed out) ... I guess both basically tell time out.

2) I would really appreciate if you can guide me on how to access localhost through an actual device because emulators are usually very slow. I once again tried running it on an actual device through the help of the internet but here again I get one of the two errors mentioned in the previous point.

3) Can you also suggest some faster and possibly lightweight emulators? Though I have 8GB RAM but AVD as well as Xamarin Android Player both take so much time (and often eventually crash) as if I'm trying to run them on a 2GB machine!

Thank you.


  • MihaMarkicMihaMarkic SI ✭✭✭✭

    Localhosts are accessible only to local machine. Thus it works on laptop since you are running it on laptop but it doesn't on emulator or device, since you aren't running it there.
    One way is to open your service (IISExpress needs some config editing, firewall has to be configured properly) and then access it using either IP or host name.
    As per emulators, the Android best one is Genymotion.

  • astahirastahir USMember ✭✭

    @MihaMarkic - thanks for the response.

    1) I have tried following the link for IISExpress configuration but I did not find a folder at %userprofile%\documents\iisexpress\ ... so not sure what to do next!

    2) I had already allowed inbound as well as outbound connections to my port 16299 for Windows Firewall but to no avail.

    3) I will download and install Genymotion now and let you know how did it go.

    By the way, I would prefer if you can tell me how to access localhost from actual device connected via USB to my laptop as I have the device with me.

  • MihaMarkicMihaMarkic SI ✭✭✭✭
    1. Are you using IIS Express in first place? Or IIS? Something else?
    2. Test from a browser from another (virtual) machine.

    Accessing it should be done as devices on same network. AFAIK there is no direct way other than through TCP/IP.

  • astahirastahir USMember ✭✭

    Sorry, the application gets hosted to ASP.NET Development Server when I run it through Visual Studio 2010. Can you tell me what should I do?


  • MihaMarkicMihaMarkic SI ✭✭✭✭

    First make sure that the dev server and your app are accessible from outside your machine. A browser is a good starting point.

  • astahirastahir USMember ✭✭

    Thanks for getting back Miha.

    When I open the following link on my laptop, it works fine:

    Obviously there is no localhost for emulator, so I wrote this in the browser of emulator but I get "webpage not available" with an additional message saying 'request timed out':

  • astahirastahir USMember ✭✭

    Well got the web service accessible on my Genymotion emulator with the help of this:

    So I used instead of

    However the problem now is that I don't see my emulator through Xamarin Studio; what do I need to do to make it possible?

  • astahirastahir USMember ✭✭

    @MihaMarkic - I now see the emulator in the list while I start debugging from Xamarin Studio and I can also access the web service on Genymotion emulator. In other words, I can resume my work via emulator. However I still remain stuck if I wish to use an actual device instead of the emulator. Can you (or anybody else on this forum) guide me on how to achieve that?

    By the way, the problem was that the emulator needed to be connected using "abd connect #.#.#.#" command. If anybody faces a similar issue in future, please go to the following link and see the complete discussion to get the whole picture:


  • astahirastahir USMember ✭✭

    Dear Xamarin enthusiasts, I still await your guidance...

  • DannyStatenDannyStaten USMember

    Plus one on this. I have the means to get my services to a publicly visible end point, but I don't have access in my organization to update that end point regularly or to debug on that server. It certainly appears that there is a lot of difficult set up required for this. In my ideal world, there would be a simple way in a Xamarin project to add some configurations to the emulators. I know that is asking a whole lot, but it would sure be awesome.

  • jacqijvvjacqijvv USMember

    Hi all, I've written a blog post on this. It is really simple to do this using SharpProxy. The link to my article:

  • MarkZhukovskyMarkZhukovsky USMember ✭✭

    @astahir that right there is your answer, great stuff @jacqijvv !

Sign In or Register to comment.