If you are getting a following like error when you are trying to connect to a Microsoft Web Service or whatever server point that is under IIS Express you might encounter the following error:
failed to connect to /127.0.0.1 (port “Your port number here”): connect failed: ECONNREFUSED (Connection refused)
The error above is due to a loopback problem. What you need to do is do some configurations.
- Find your applicationhost.config file under your documents(usually): C:\Users\”Your account name here”\Documents\IISExpress\config
- Then find your web service binding information see the example below(the sample in the green color, the red color binding is what is by default configured).
- Add the IP address and the port to which you want to connect at from android studio. The IP address has to be your development machines IP address.
- Also you need to add new rules to your windows firewall that allows your ports through which you wish the connection to be done.
- You may need to run Visual Studio in Administrator mode
<site name=”MyFitnessTrackerWebAPI(1)” id=”17″>
<application path=”/” applicationPool=”Clr4IntegratedAppPool”>
<virtualDirectory path=”/” physicalPath=”C:\Users\Adrian Simionescu\Dropbox\MyFitnessTracker\MyFitnessTrackerWebAPI\MyFitnessTrackerWebAPI” />
<binding protocol=”http” bindingInformation=”*:52797:localhost” />
<binding protocol=”http” bindingInformation=”*:80:192.168.163.151″ />
<binding protocol=”http” bindingInformation=”*:52797:192.168.163.151″ />
After this when you start up your webservice you should be able to access your service by address or host name. Also your IIS Express hosting information should look something in the this direction(based on the configuration above):