Java web services and Android clients – I


This is the second blog post in my April vacation. My intention of this post is to share my third year Software Engineering project experience with others before forget. When I decided to do this project I was new to Android and web services. So I had to over come various problems and try various examples available on internet.

Through this post I’ll show the path worked for me along with some problems I saw and I faced. Therefore I wish this would help for those people who are new to this type of developments.

Web services

The above image shows the the basic structure of the Service Oriented Architecture (SOA). There are so many good resources about SOA for learning.

The thing I want to mention here is for this purpose we want at least 2 things, a web server and a client (service requester). Program in those 2 sides need not to be in same language, but need to support same method of communication. In here I’ll use SOAP (Simple Object Access Protocol) messages, but there are many other methods too.

Creating a web service

For this purpose you need to have following things.

  • Eclipse EE edition
  • Axis2 .war file
  • Tomcat server
  • Other libraries according to your need (eg: JDBC driver, JUnit… etc.)

Creating the web service can be done in this way: Click here

(You can use place Axis2 .war file inside ..\Apache Software Foundation\Tomcat 7.0\webapps  folder without downloading binaries and configure to that)

Actually, web service is nothing other than one .java file is set to communicate with client. Other files inside need not to have .wsdl files. You can also use libraries just as you do in desktop application.

Problems You may face
  1. Fail to build a Dynamic web project – some times you face this error due to a bug in eclipse. A solution would be to import a previously created Dynamic web project through File->Import, and continue the rest.
  2. Libraries filed to support – When you use an external library you need to set build path of project to that .jar file, add .jar file to project’s Project_Name\WebContent\WEB-INF\lib folder and refresh that folder in Eclipse package explorer.

Example web service

Following code is the interface that client connect and used to create the WSDL file. This example is just to show how client use each method in web service.

import java.sql.DriverManager;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
 * @author BUDDHIMA
public class EmergencyAid {

     * @param args the command line arguments
    public String getLocations(String inputLocation) {

	String output;

         // Code for processing data and assign value to "output" string.
	}catch(Exception e){
        return output;

Basically communication between web service and client is done using Strings or other primary data types in Android. But If you rally want to exchange custom objects or Lists you have to convert them in to String (will discuss an easy way for this later).

Since this post is getting longer I’m moving client part to next post.


1. Eclipse WTP tutorial:

2. Christon’s tutorial:

Alternative ways of creating Axis 2 web services:

3. WSO2 oxygen tank:

4. Youtube demo:

Not only Axis 2, but also there are other web service engines available (eg: CFX )


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s