Android kSoap2 web service Parsing Data
In this tutorial for Android ksoap2 web service . we can passing data through web service and store the data in web server.
how to read and parse JSON or XML, but another (pretty big) format is SOAP. In this post we will see how you make a application that reads and parses SOAP data into a Android application!
first we need ksoap2-android-assembly-2.4-jar file. download this jar file and put your workspace lib folder.
Download latest ksoap Jar File
Note: At the time of writing this the most recent version is 2.5.4 .
Download ksoap2 JAR File
Source code
package com.soap;
import java.io.*;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class Mainactivity extends Activity {
ImageButton b;
private final String NAMESPACE = "http://str7......com/";
private final String METHOD_NAME = "InsertChild";
private final String SOAP_ACTION = "http://str7..........com/InsertChild";
private final String URL = "http://str7...........com/custodyapp.asmx";
// protected static final String END_DOCUMENT =null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
/// request.addProperty("ChildName","ijay");
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ChildName","Vijay");
request.addProperty("GroupID","15");
request.addProperty("ParentID","15");
request.addProperty("Remarks","good");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request); .
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
Log.i("Result........................", result.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // This sends a soap
Log.i(envelope.bodyIn.toString(),"....................");
}}
In this tutorial for Android ksoap2 web service . we can passing data through web service and store the data in web server.
how to read and parse JSON or XML, but another (pretty big) format is SOAP. In this post we will see how you make a application that reads and parses SOAP data into a Android application!
first we need ksoap2-android-assembly-2.4-jar file. download this jar file and put your workspace lib folder.
Download latest ksoap Jar File
Note: At the time of writing this the most recent version is 2.5.4 .
- Just click the most recent version
- search for the jar file with dependencies.
- download it by right clicking the link "Raw file"
- then clicking "Save as ...".
- Save it inside your project folder so you can link it easily.
Download ksoap2 JAR File
Source code
package com.soap;
import java.io.*;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class Mainactivity extends Activity {
ImageButton b;
private final String NAMESPACE = "http://str7......com/";
private final String METHOD_NAME = "InsertChild";
private final String SOAP_ACTION = "http://str7..........com/InsertChild";
private final String URL = "http://str7...........com/custodyapp.asmx";
// protected static final String END_DOCUMENT =null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
/// request.addProperty("ChildName","ijay");
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ChildName","Vijay");
request.addProperty("GroupID","15");
request.addProperty("ParentID","15");
request.addProperty("Remarks","good");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request); .
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
Log.i("Result........................", result.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // This sends a soap
Log.i(envelope.bodyIn.toString(),"....................");
}}
Hai, good tutorial :)
ReplyDeleteI am getting the response as 1 in logcat for my webservices program and I am finding it difficult to show an alert dialouge like "success"
I want to parse and store the value in a local variable I think
how can I do this?
Hai, thank you for this one can you give me any advice about login in particular web service...
ReplyDeletesame u have to call login webservice..
ReplyDeleteNice Tutorial:)
ReplyDeleteHi.,
ReplyDeleteits nice tutorial.But i wish to need creating soap webservice in java project afterthat calling dis java soap webservices in android application.how can i do.please guide me.
I'm hunting for a 10" screen mini laptop with wireless. I'm not sure just what a good brand to get is. I need 1 with a great deal of memory. I've seen the Acer aspire one and that appears pretty good but I desire more options..
ReplyDeleteCheck out my site ... Lonnie Callery @ www.best-laptops-under-500.net
kSoap2 web service parsing Data How you handle OutOf memory exception ?or how you handle heap memeory size isuue?
ReplyDeletenice one
ReplyDeleteMagnificent site. Plenty of useful information here. I am
ReplyDeletesending it to a few buddies ans additionally sharing in delicious.
And of course, thank you in your effort!
Feel free to surf my webpage - my blog
send to dis id ramesh22kvr@gmail.com
ReplyDeletemy no 8341617367
i want free android documentation send to above id
Very nice post. I јust stumbled upon your weblog anԁ wanteԁ tо
ReplyDeletesаy that I've truly enjoyed browsing your blog posts. In any case I'll be ѕubscrіbing to уour
гss feed and I hopе уοu writе again very
sοon!
Here is my homepage : brand name laptops
My prоgrammer iѕ trying tο perѕuade me to move to
ReplyDelete.net from PHP. I have alωays dislіkеd the ideа becausе of the costs.
But hе's tryiong none the less. I've been using
Μoѵable-tуpе on various
websiteѕ for about a year and am nеrvous about ѕwitсhing to another platform.
Ι have hеard goоd things about blogengine.
net. Ιs there a way I сan import all my wοrdpress content into it?
Αny hеlp would be grеatly apрrеciаteԁ!
My page - http://raspberryketoned.co.uk
where is the parsing man..?????
ReplyDeleteit just gets the xml in a Soap Object...
u didn't use the pullparser...please complete it..