Thursday, June 30, 2011

Android kSoap2 web service parsing Data

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 .
  • 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.
Note: add the jar file to the project. ( Project properties -> Java build path -> Add JAR's )
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(),"....................");
    }}

13 comments:

  1. Hai, good tutorial :)

    I 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?

    ReplyDelete
  2. Hai, thank you for this one can you give me any advice about login in particular web service...

    ReplyDelete
  3. same u have to call login webservice..

    ReplyDelete
  4. Hi.,

    its 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.

    ReplyDelete
  5. 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..
    Check out my site ... Lonnie Callery @ www.best-laptops-under-500.net

    ReplyDelete
  6. kSoap2 web service parsing Data How you handle OutOf memory exception ?or how you handle heap memeory size isuue?

    ReplyDelete
  7. Magnificent site. Plenty of useful information here. I am
    sending 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

    ReplyDelete
  8. send to dis id ramesh22kvr@gmail.com
    my no 8341617367
    i want free android documentation send to above id

    ReplyDelete
  9. Very nice post. I јust stumbled upon your weblog anԁ wanteԁ tо
    sа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

    ReplyDelete
  10. My prоgrammer iѕ trying tο perѕuade me to move to
    .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

    ReplyDelete
  11. where is the parsing man..?????
    it just gets the xml in a Soap Object...
    u didn't use the pullparser...please complete it..

    ReplyDelete

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...