java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
Since you have not specified you are connected to a server from the device or emulator so I guess you are using your application in the emulator.
If you are referring your localhost on your system from the Android emulator then you have to use http://10.0.2.2:8080/
Because Android emulator runs in a Virtual Machine therefore here 127.0.0.1
or localhost
will be emulator's own loopback address.
Refer: Emulator Networking
in android
Replace: String webServiceUrl = "http://localhost:8080/Service1.asmx"
With : String webServiceUrl = "http://10.0.2.2:8080/Service1.asmx"
Good luck!
localhost and 127.0.0.1 are both ways of saying 'the current machine'. So localhost on your PC is the PC and localhost on the android is the phone. Since your phone isn't running a webserver of course it will refuse the connection.
You need to get the IP address of your machine (use ipconfig on windows to find out) and use that instead of 127.0.0.1. This may still not working depending on how your network/firewalls are set up. But that is a completely different topic.
- Add Internet permission in Androidmanifest.xml file
uses-permission android:name="android.permission.INTERNET
- Open cmd in windows
- type "ipconfig" then press enter
- find IPv4 Address. . . . . . . . . . . : 192.168.X.X
- use this URL "http://192.168.X.X:your_virtual_server_port/your_service.php"