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(),"....................");
}}