views:

76

answers:

2

Hi!

What is the best way to deal with web services in Android? I have been looking at KSoap2 library and RESTful web services.

I got one working with KSoap2, but only when the web service is on a remote server, not on localhost. I have tried to redirect the ports for incoming and outgoing as it says on the android dev site, i have used the ip of the network i am on, my own ip and the localhost-ip (it says on the site that one cannot use localhost cause that is the emulators own loop-back network. None works.

With RESTful webservices, i have only tried a tutorial where a google app engine is used as server if i understood it right. Is it easy to connect a RESTful web service to a database. I need to have a database connection in my applikation, which one is normally used with REST?

Sorry for the confused question, it's been many days of trying to sort just the alternatives out, and the more I look the confused I get.

THanks in advance for any help! /AK

A: 

To connect to a webserver running on the same machine as your android emulator you need to use the IP address 10.0.2.2 see here:

Once you have your app in the emualtor connecting successfully to a webserver running on the same machine you can then decide how best to send data between the 2. If you chose to use xml and/or SOAP then kSoap2 is your best bet. Using a RESTful webserice is much more "light weight" and just refers to using normal HTTP and urls for your app to get/send data to the app running on your webserver.

Maks
Hi! I have tried using 10.0.2.2 with and without specified ports but however I do it I get connection refused. The only time i get another answer is when i use the ip of my network, then I get the "excption...". I have tried the different combinations, can there be something else I am overseeing, i am a beginner, so something obvious could still be missed.
Anna-Karin
A: 

Hi,

I would go for REST for sure. You could also use JSon instead of XML. Android has a built in support for JSon and REST becames quite easy to use and maintain with JAX-RS specification. It is also as mentioned by Maks a light weigth approach. If you have a more complex scenario you could use some JSon librarie like GSon for JSon parser between java objects and JSon. Also if you decide to go for Seam in the server side I would suggest you to use RestEasy.

[]s

Marcos Maia