Click here to Skip to main content
12,827,730 members (46,524 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


100 bookmarked
Posted 24 Sep 2010

Step by Step Method to Access Webservice from Android

, 24 Sep 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
How to access webservice from Android mobile application

System Requirements

The sections below describe the system and software requirements for developing Android applications using the Android SDK.

Supported Operating Systems

  • Windows XP (32-bit) or Vista (32- or 64-bit)
  • Mac OS X 10.5.8 or later (x86 only)
  • Linux (tested on Linux Ubuntu Hardy Heron)

Supported Development Environments

Eclipse IDE

  • Eclipse 3.4 (Ganymede) or 3.5 (Galileo)

Caution: There are known issues with the ADT plugin running with Eclipse 3.6. Please stay on 3.5 until further notice.

  • Eclipse JDT plugin (included in most Eclipse IDE packages)
  • If you need to install or update Eclipse, you can download it from

    Several types of Eclipse packages are available for each platform. For developing Android applications, we recommend that you install one of these packages:

  • Eclipse IDE for Java EE Developers
  • Eclipse IDE for Java Developers
  • Eclipse for RCP/Plug-in Developers
  • Eclipse Classic (versions 3.5.1 and higher)
  • JDK 5 or JDK 6 (JRE alone is not sufficient)
  • Android Development Tools plugin (optional)
  • Not compatible with Gnu Compiler for Java (gcj)

Hardware Requirements

The Android SDK requires disk storage for all of the components that you choose to install. The table below provides a rough idea of the disk-space requirements to expect, based on the components that you plan to use.

Component type

Approximate size


SDK Tools

50 MB


Android platform (each)

150 MB

At least one platform is required.

SDK Add-on (each)

100 MB


USB Driver for Windows

10 MB

Optional. For Windows only.

Samples (per platform)



Offline documentation

250 MB


Note that the disk-space requirements above are in addition to those of the Eclipse IDE, JDK, or other prerequisite tools that you may need to install on your development computer.

Installing the ADT Plugin for Eclipse

  1. Start Eclipse, then select Help > Install New Software.
  2. In the Available Software dialog, click Add....
  3. In the Add Site dialog that appears, enter a name for the remote site (for example, "Android Plugin") in the "Name" field.

In the "Location" field, enter this URL:

Note: If you have trouble acquiring the plugin, you can try using "http" in the URL, instead of "https" (https is preferred for security reasons).

Click OK.

  1. Back in the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools. Click Next.
  2. In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish.
  3. Restart Eclipse.

Configuring the ADT Plugin

Once you've successfully downloaded ADT as described above, the next step is to modify your ADT preferences in Eclipse to point to the Android SDK directory:

  1. Select Window > Preferences... to open the Preferences panel (Mac OS X: Eclipse > Preferences).
  2. Select Android from the left panel.
  3. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.

Click Apply, then OK.

Creating an Android Project

The ADT plugin provides a New Project Wizard that you can use to quickly create a new Android project (or a project from existing code). To create a new project:

  1. Select File > New > Project.
  2. Select Android > Android Project, and click Next.
  3. Select the contents for the project:
    • Enter 'AndroidWSAccess'. This will be the name of the folder where your project is created.
    • Under Contents, select Create new project in workspace. Select your project workspace location.
    • Under Target, select an Android target to be used as the project's Build Target. The Build Target specifies which Android platform you'd like your application built against.

      Unless you know that you'll be using new APIs introduced in the latest SDK, you should select a target with the lowest platform version possible.

      Note: You can change your the Build Target for your project at any time: Right-click the project in the Package Explorer, select Properties, select Android and then check the desired Project Target.

    • Under Properties, fill in all necessary fields.
      • Enter an Application name as 'AndroidWSAccess'. This is the human-readable title for your application — the name that will appear on the Android device.
      • Enter a Package name as ''. This is the package namespace (following the same rules as for packages in the Java programming language) where all your source code will reside.
      • Select Create Activity (optional, of course, but common) and enter a name (give 'FirstAppUI') for your main Activity class.
      • Enter a Min SDK Version. This is an integer that indicates the minimum API Level required to properly run your application. Entering this here automatically sets the minSdkVersion attribute in the <uses-sdk> of your Android Manifest file. If you're unsure of the appropriate API Level to use, copy the API Level listed for the Build Target you selected in the Target tab.
  4. Click Finish.

Tip: You can also start the New Project Wizard from the New icon in the toolbar.

Once you complete the New Project Wizard, ADT creates the following folders and files in your new project:

Includes your stub Activity Java file. All other Java files for your application go here.
<Android Version>/ (e.g., Android 2.2/)

Includes the android.jar file that your application will build against. This is determined by the build target that you have chosen in the New Project Wizard.


This contains the Java files generated by ADT, such as your file and interfaces created from AIDL files.

This is empty. You can use it to store raw asset files.
A folder for your application resources, such as drawable files, layout files, string values, etc.
The Android Manifest for your project.
This file contains project settings, such as the build target. This file is integral to the project, as such, it should be maintained in a Source Revision Control system. It should never be edited manually — to edit project properties, right-click the project folder and select "Properties".

Creating an AVD

An Android Virtual Device (AVD) is a device configuration for the emulator that allows you to model real world devices. In order to run an instance of the emulator, you must create an AVD.

To create an AVD from Eclipse:

  1. Select Window > Android SDK and AVD Manager, or click the Android SDK and AVD Manager icon in the Eclipse toolbar.
  2. In the Virtual Devices panel, you'll see a list of existing AVDs. Click New to create a new AVD.
  3. Fill in the details for the AVD.

    Give it a name, a platform target, an SD card size, and a skin (HVGA is default).

    Note: Be sure to define a target for your AVD that satisfies your application's Build Target (the AVD platform target must have an API Level equal to or greater than the API Level that your application compiles against).

  4. Click Create AVD.

Your AVD is now ready and you can either close the SDK and AVD Manager, create more AVDs, or launch an emulator with the AVD by selecting a device and clicking Start.

Code your class like below:


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class FirstAppUI extends Activity {

	private static final String NAMESPACE = "com.service.ServiceImpl";
	private static final String URL = 
	private static final String SOAP_ACTION = "ServiceImpl";
	private static final String METHOD_NAME = "message";
	private static final String[] sampleACTV = new String[] {
	"android", "iphone", "blackberry"

	public void onCreate(Bundle savedInstanceState) {
		ArrayAdapter<String> arrAdapter = new ArrayAdapter<String>
		(this, android.R.layout.simple_dropdown_item_1line, sampleACTV);

		AutoCompleteTextView ACTV = (AutoCompleteTextView)findViewById

		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 		
		SoapSerializationEnvelope envelope = 
			new SoapSerializationEnvelope(SoapEnvelope.VER11); 

		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

		try {, envelope);
			SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
			ACTV.setHint("Received :" + resultsRequestSOAP.toString());
		} catch (Exception e) {

Insert AutoCompleteTextView to your res>layout >main.xml as:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout android:id="@+id/LinearLayout01"

         android:hint="This is Hint"         
         android:width="240px" />  


Insert Internet access permission to your mobile application in AndroidManifest.xml file as:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".FirstAppUI"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-sdk android:minSdkVersion="8" />



<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace= 
	xmlns:impl="" xmlns:intf= 
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
  <schema elementFormDefault="qualified" 
      targetNamespace="" xmlns="">
   <element name="message">
   <element name="messageResponse">
      <element name="messageReturn" type="xsd:string"/>

   <wsdl:message name="messageResponse">
      <wsdl:part element="impl:messageResponse" name="parameters">
   <wsdl:message name="messageRequest">
      <wsdl:part element="impl:message" name="parameters">
   <wsdl:portType name="ServiceImpl">
      <wsdl:operation name="message">
         <wsdl:input message="impl:messageRequest" name="messageRequest">
         <wsdl:output message="impl:messageResponse" name="messageResponse">
   <wsdl:binding name="ServiceImplSoapBinding" type="impl:ServiceImpl">
      <wsdlsoap:binding style="document" 
      <wsdl:operation name="message">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="messageRequest">
            <wsdlsoap:body use="literal"/>
         <wsdl:output name="messageResponse">
            <wsdlsoap:body use="literal"/>
   <wsdl:service name="ServiceImplService">
      <wsdl:port binding="impl:ServiceImplSoapBinding" name="ServiceImpl">
         <wsdlsoap:address location=



  • 24th September, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mihira Prasanna
Software Developer Synapsys Ltd, DFCC Bank, Sri Lanka
Sri Lanka Sri Lanka
Researching innovation of software technology.

You may also be interested in...


Comments and Discussions

QuestionHow to create a localhost HTTP url for the wsdl file? Pin
Aniket Kapse24-Jan-14 2:38
memberAniket Kapse24-Jan-14 2:38 
GeneralMy vote of 1 Pin
Paul Conrad30-May-13 8:06
memberPaul Conrad30-May-13 8:06 
QuestionUnfortunately stopped working Pin
Member 993657823-Mar-13 9:57
memberMember 993657823-Mar-13 9:57 
AnswerRe: Unfortunately stopped working Pin
Member 111485173-Nov-14 19:01
memberMember 111485173-Nov-14 19:01 
QuestionUnfortunately Stopped Working with this code? Pin
Shahbazkhanmd17-Feb-13 3:20
memberShahbazkhanmd17-Feb-13 3:20 
Questioncall web service got e=null exception Pin
sonichanxiao19-Jul-12 23:21
membersonichanxiao19-Jul-12 23:21 
Questionandroid Webservice error font UTF8 Pin
daitranthanhhoa18-Jun-12 19:52
memberdaitranthanhhoa18-Jun-12 19:52 
GeneralMy vote of 1 Pin
Hai-Binh LE28-May-12 0:05
memberHai-Binh LE28-May-12 0:05 
QuestionServiceImpl.wsdl Pin
Yarakam Bharathi23-May-12 22:37
memberYarakam Bharathi23-May-12 22:37 
QuestionI have a web service url rather than a wsdl file.How can i acces that Pin
kiranmatrixlee22-Apr-12 1:28
memberkiranmatrixlee22-Apr-12 1:28 
GeneralMy vote of 1 Pin
keret18-Mar-12 7:35
memberkeret18-Mar-12 7:35 
QuestionWhere to add ServiceImpl.wsdl in android app, help! Pin
rufj28-Dec-11 3:30
memberrufj28-Dec-11 3:30 
GeneralMy vote of 5 Pin
Member 82962467-Dec-11 12:00
memberMember 82962467-Dec-11 12:00 
QuestionGetting ClassCastException or org.xmlpull.v1.XmlPullParserException Pin
harshawardhan.sd15-Nov-11 2:58
memberharshawardhan.sd15-Nov-11 2:58 
AnswerRe: Getting ClassCastException or org.xmlpull.v1.XmlPullParserException Pin
raja.abz11-Sep-12 23:57
memberraja.abz11-Sep-12 23:57 
GeneralMy vote of 1 Pin
Michael Ulmann19-Oct-11 17:56
memberMichael Ulmann19-Oct-11 17:56 
GeneralMy vote of 5 Pin
azizsurani4-Oct-11 22:16
memberazizsurani4-Oct-11 22:16 
GeneralMy vote of 5 Pin
msameera24-Sep-11 7:14
membermsameera24-Sep-11 7:14 
GeneralMy vote of 3 Pin
lijo011@yahoo.com6-Sep-11 19:58
memberlijo011@yahoo.com6-Sep-11 19:58 
QuestionKSOAP_ACTION and NAMESPACE value Pin
Hoai_Nguyen28-Aug-11 4:26
memberHoai_Nguyen28-Aug-11 4:26 
AnswerRe: KSOAP_ACTION and NAMESPACE value Pin
Hoai_Nguyen28-Aug-11 4:34
memberHoai_Nguyen28-Aug-11 4:34 
Questionjar file location Pin
anjalikulkarni24-Aug-11 3:44
memberanjalikulkarni24-Aug-11 3:44 
Generalsend image captured from camera Pin
sharan kumar14-Jun-11 1:18
membersharan kumar14-Jun-11 1:18 
GeneralRe: send image captured from camera Pin
ozharugold4-Sep-11 17:19
memberozharugold4-Sep-11 17:19 
GeneralWSTL location Pin
Member 78875395-May-11 2:27
memberMember 78875395-May-11 2:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 24 Sep 2010
Article Copyright 2010 by Mihira Prasanna
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid