Basic KSOAP Android Tutorial


This is a basic KSOAP Android tutorial - here I will show you how to get started with KSOAP on Android. As you may know, we often want to access Web services via hand-held devices, and most likely you will run into trouble parsing the WSDL and the SOAP messages. Since I come from a .NET background, once I started developing on Android, I realized how much work has been Visual Studio doing for me.

That thought took me to search for a framework or library to help me consume Web Services with Android. I ran into KSOAP2, which seemed like a good library, but unfortunately, very badly documented for most scenarios, like passing or returning complex objects, working with arrays of objects or even working with dates.



All of this I needed to find out by myself and this is why I decided to write this tutorial. So, let's begin.

Getting Started with KSOAP on Android


First things first, so you should now go ahead and download the KSOAP library from Sourceforge Google code (*UPDATE* thanks Freddy):
http://code.google.com/p/ksoap2-android/downloads/detail?name=ksoap2-android-assembly-2.4-jar-with-dependencies.jar&can=2&q=


Then copy and paste the KSOAP library in the folder where your Android project will reside. Open Eclipse, start a new Android Project, right-click on the project's name and choose Properties, like this:


The next thing you need to do is to Add the KSOAP .JAR into the Android Project:




Go ahead an press Add JARs... button. Then navigate to the folder where your KSOAP library is and select it. Once you have this done, you are ready to start working with your Web Service library.

Simple Web Service Calls with KSOAP


First, let's take a look at our web service call in Visual Studio:

[WebService(Namespace = "http://vladozver.org/")]
public class SimpleWebServices : System.Web.Services.WebService
{
      [WebMethod]
      public int GetSumOfTwoInts(int Operand1, int Operand2 )
      {
         return Operand1 + Operand2;
      }
}

The service is deployed on my local machine which is on the address: 192.168.1.3. Pay attention on the ending "/" in the Namespace.

Now, KSOAP finally.

KSOAP relies on a basic object called SoapObject. For this SoapObject, there are 3 variables that are important:
The Web Service Namespace
The Web Service Method Name
The Web Service URL

There is another extra variable which is important and is called SOAP_ACTION, but that is basically a concatenation of the Namespace and Method name:

SOAP_ACTION = NAMESPACE + METHOD_NAME;

For now we will create 3 strings for the respective variables:

String NAMESPACE = "http://vladozver.org/";
        String METHOD_NAME = "GetSumOfTwoInts";
        String SOAP_ACTION = "http://vladozver.org/GetSumOfTwoInts";
        String URL = "http://192.168.1.3/VipEvents/Services/BasicServices.asmx";

Then we will create the SoapObject:
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

Parameters in KSOAP are passed via PropertyInfo class instances, so we will create some of those:

PropertyInfo pi = new PropertyInfo();
        pi.setName("Operand1");
        pi.setValue(2);
        pi.setType(int.class);
        Request.addProperty(pi);

        PropertyInfo pi2 = new PropertyInfo();
        pi2.setName("Operand2");
        pi2.setValue(5);
        pi2.setType(int.class);
        Request.addProperty(pi2);

Then we will create another important KSOAP object, and that is Soap Envelope:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);

Because our Web Service is .NET based, we need to set the .dotNet property to true.
Next step is to create a Transport object:

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

Lastly, we need to invoke the web service and obtain the result:

try
            {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapObject response = (SoapObject)envelope.getResponse();
                int result =  Integer.parseInt(response.getProperty(0).toString());
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }


That is basically it! I hope you will find this tutorial helpful, as I see that many people are looking for a simple Getting started tutorial on KSOAP Android. For more advanced usage of KSOAP, refer to my other posts on this topic.

442 comments:

«Oldest   ‹Older   401 – 442 of 442
Reshma said...

Wonderful post and more informative!keep sharing Like this!
Salesforce Training in Hyderabad
Salesforce Training in Pune

BK-25 said...

Very Informative blog thank you for sharing. Keep sharing.

Best software training institute in Chennai. Make your career development the best by learning software courses.

informatica training in chennai
android training in chennai
power bi training in chennai
Docker Training in Chennai
ios training in chennai
Xamarin Training in Chennai
msbi training in chennai

Keerthi55 said...

Fantastic article post.Really thank you! Awesome.
ms azure online training
best azure online training

Block said...

Thanks a lot very much for the high quality and results-oriented help.
I won’t think twice to endorse your blog post to anybody who wants
and needs support about this area.
dba course in chennai
java training institute in chennai
node js course in chennai

Alexander john said...

Hey! What a wonderful blog. I loved your blog. QuickBooks is the best accounting software; however, it has lots of bugs like QuickBooks for MAC Support . To fix such issues, you can contact experts via QuickBooks Support Phone Number (855)963-5959.

ben said...

Special school
Donate to children in need

Unknown said...

nice blog. We provide quickbooks customer service you can contact us on call.

Quickbooks Customer Service said...

Awesome bolg.if you looking for a best quickbook customer service you can contact us on phone call.+1 888-272-4881

QuickBooks Support service said...

nice blog. if you are looking for Quickbook support service you can contact us at.+1 866-669-5

Quickbooks support Service said...

good contant!! we provide bestest service and you are looking for QUICKBOOKS SUPPORT SERVICE SUPPORT. you can contact us at.+18555484814

quickbooks support service said...

nice blog. if you are looking forQuickbooks support service.you can contact us at.+18776030806

Quickbooks customer service said...

Nice content!!
if you are looking for a best Quickbook support serviceyou can reach us at.+1 855-444-2233

Unknown said...


Business Analyst Certification Training
Django Course Online

Pavithra Devi said...

Great post. Thanks for sharing such a useful blog.
Artificial Intelligence Course in porur
Artificial Intelligence Course in Chennai

mgowrimagalingam@gmail.com said...

I'm really for appreciate this blog useful in blog thank you for share

Jai Jaiswal said...

Thanks for sharing amazing blog. Yoga can makes the easy to control your mind ,to understand about your mind and to keep calm your mind. types of yoga , yogainfo ,theyogainfo.comyou reach us at

Jai Jaiswal said...

Thanks for sharing good blog. Yoga have the power to change your mentality that how to think ,how to control your mind and how to use it. yogainfo , yoga asanas, theyogainfo.com you reach us at

Matt Reeves said...

Mindblowing blog very useful thanks
Digital Marketing Course in Porur
Digital Marketing Course in OMR

Matt Reeves said...

This post is so interactive and informative.keep update more information...
SEO Training in Tambarama
SEO Training in Chennai

Quickbooks Customer Service said...

QuickBooks also offers live chat support as well as email support which allows businesses who are out of the office or at home to access QuickB's qualified help desk staff. The QuickBooks Service Number is +1 888-471-2380 and is always available 24 hours a day to serve you with all your QuickBooks questions.

Quickbooks Support Phone Number.+18666695068,NJ said...

When you or your company need help with QuickBooks or any other aspect of your business, dial Quickbooks Suppport Phone Number +1 866-669-5068,NJ.

Quickbooks Support Phone Number.+1 855-444-2233,Hawaii said...

If you're looking for help in using it, just dial QuickBooks Customer Service Phone Number +1 855-444-2233 to speak with a live representative. They'll be able to answer any questions about the software and help get you up and running.

Quickbooks Support Phone Number.+1 888-210-4052,PA. said...

QuickBooks also offers live chat support as well as email support which allows businesses who are out of the office or at home to access QuickB's qualified help desk staff. The QuickBooks Service Number is +1 888-210-4052 and is always available 24 hours a day to serve you with all your QuickBooks questions.

Jai Jaiswal said...

Nice blog. If you are looking for a best knowledge of yoga Yoga, yogainfo , yoga asanas you reach us at

Creative Studio said...

HELLO! the information is very good andinteresting..please keep updating it!
Thanks!

vepsun said...

Best AWS Training provided by Vepsun in Bangalore for the last 12 years. Our Trainer has more than 20+ Years
of IT Experience in teaching Virtualization and Cloud topics.. we are very delighted to say that Vepsun is
the Top AWS cloud training Provider in Bangalore. We provide the best atmosphere for our students to learn.
Our Trainers have great experience and are highly skilled in IT Professionals. AWS is an evolving cloud
computing platform provided by Amazon with a combination of IT services. It includes a mixture of
infrastructure as service and packaged software as service offerings and also automation. We have trained
more than 10000 students in AWS cloud and our trainer Sameer has been awarded as the best Citrix and Cloud
trainer in india.

Anonymous said...

Very Nice Blog Thanks For Sharing with us are you are looking Quickbooks Service Please get in touch with quickbooks support phone number for quick Response

Anonymous said...

Great Blog For Web Service If you want to also get help for Quickbooks Service then contact our
Quickbooks customer service +18777541114 Team For Quick Response

Anonymous said...

I really enjoyed Your Post . I definitely update your post another platform .
you can get Service click on it Quickbooks Error Support and call +1-855-977-7463

Anonymous said...
This comment has been removed by the author.
Anonymous said...
This comment has been removed by the author.
Anonymous said...

Thanks For Sharing awesome blog if you are suffering any Quickbooks issue while Quickbooks Update then you can get solution from
Quickbooks Error Support +1 (213) 417-0111

huzaifa siddique said...

I like it!
Nice collection, you can also visit our Designer Wedding Dresses

huzaifa siddique said...

I like it!
Nice blogs, you can also visit our Designer Wedding Dresses

Education Hub said...

I just loved your article on the beginners guide to starting a blog. If somebody take this blog article seriously
in their life, he/she can earn his living by doing blogging. Thank you for this article.
Rice Milling Technology
College Courses

Denkpopo said...

Manufacturing Software Price

Education Hub said...

Happy to read the informative blog. Thanks for sharing.
Dry Cleaning Business
Broiler Poultry Farming

Chaitanya said...

Wow, that’s what I was exploring for, what a material! present here at this website, thanks admin of this web site.

Power BI Online Training

Umurs said...

izmir
Erzurum
Diyarbakır
Tekirdağ
Ankara
2Y16WY

Per2i said...

elazığ
erzincan
bayburt
tunceli
sakarya
KP4İ7

NeonStormPirate256 said...

görüntülüshow
ücretli show
2C7N

lisad.lusk said...

Are you an app development company looking to expand your expertise in Android development? Look no further! In this basic KSOAP Android tutorial, we will guide you through the process of integrating KSOAP into your Android applications.

«Oldest ‹Older   401 – 442 of 442   Newer› Newest»

Post a Comment