Search code examples
c#androidwcfxamarin.android

Connection refused error when connecting a WCF to a Xamarin.Android project


So I am new to Xamarin and WCF. However, that wasn't gonna stop me from using those new technologies! Anyways, I started with this tutorial: https://learn.microsoft.com/en-us/xamarin/cross-platform/data-cloud/web-services/walkthrough-working-with-wcf

I followed it step by step to no avail(numerous errors when building the project). I then decided to use the sample code for the same tutorial provided here: https://developer.xamarin.com/samples/mobile/WCF-Walkthrough/

(click Download on the top right corner).

When running this project (Android part), I get an error "Connection refused". I'm guessing this is a generic error message that occurs even if the WCF wasn't even found (because I changed configurations to test that theory).

Can anyone help me solve this error?

Other things to note:

I have turned my firewall off (just in case). Based on the tutorial I did all of the IIS changes that were in there. I also made changes to the application.config file to have it contain my IP address. I have been stuck on this now for 3 days. It would be really useful to solve this error, because anyone else using that tutorial could also actually get the project working.

Thanks In Advance!


Solution

  • When you use the emulator, you cant just refer to LocalHost. The Localhost refers to the device on which the code is running, in this case the emulator.

    If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead.

    More info here

    Set up Android Emulator networking