Sunday, January 23, 2011

Consuming SOAP web services in Android

     it’s pretty common for android developers to use web services, mmm.. no, let me rephrase,

it’s pretty common for every developer to write code which consumes data from a web service, because this is the world we’re living in at the moment, a server serves as a data host for different clients and other servers using data protocols.

the most common protocol you’ll use is REST, which means that all the data transferred is basically represented as Json Strings, which is probably the best way to do it, because Json is very easy to understand, parse and generate both on client side, and on server side.

Android has great built in support for consuming Restful web services, but it lack support in SOAP web services. Odds are you’ll probably encounter a web service of this sort. so what can we do?

A suggested and common solution is to use the free open source library called KSOAP2, which provides us with an easy API for generating requests and parsing responses in a SOAP format.

how do we use it?

source code is available here: http://code.google.com/p/ksoap2-android/

once downloaded, it can be included in the build path of the project, and if in some way you have a web service which forces you to work in a specific formatting in the requests, you can download the entire source code and start modifying it as you wish Smile