Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

calling webservices that return complexTypes in android using ksoap2

Ads

 
 

Share on Google+Share on Google+

uthpala
calling webservices that return complexTypes in android using ksoap2
0 Answer(s)      4 years and 10 months ago
Posted in : WebSevices

Here's my code for android application,to call aweb service method and return a complexType object from it.

package com.example.gramaniladharidetails;

import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.MarshalFloat;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

  public class GramaNiladhari extends Activity {
private static String SOAP_ACTION1= "http://localhost/getGramaNiladhariData";
private static String NAMESPACE = "http://119.235.4.217/";
private static String METHOD_NAME1 = "getGramaNiladhariData";
private static String URL = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grama_niladhari);


    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            final String gndLifeCode = prov;
            String LifeCode = "3-2-09-060";
            request.addProperty("gndLifeCode", LifeCode);
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);


            SupportThread st = new SupportThread();
            Log.i("Request", request.toString());
            st.execute(request);

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_grama_niladhari, menu);
    return true;
}

private class SupportThread extends
        AsyncTask<SoapObject, Object, SoapObject> {

    @Override
    protected SoapObject doInBackground(SoapObject... req) {
        SoapObject result = null;
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.setOutputSoapObject(req[0]);
        envelope.addMapping(NAMESPACE, "SerializeInfo",
                new SerializeInfo().getClass());

        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(envelope);

        envelope.dotNet = true;

        try {
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            androidHttpTransport.debug = true;

            androidHttpTransport.call(SOAP_ACTION1, envelope);
            SoapObject result = (SoapObject) envelope.getResponse();



            if (envelope.bodyIn instanceof SoapFault) {
                String str = ((SoapFault) envelope.bodyIn).faultstring;
                Log.i("*******", str);

            } else {
                int elementCount = result.getPropertyCount();

                if (elementCount > 0) {
                    String element;

                    for (int i = 0; i < elementCount; i++) {


                        element = result.getProperty(i).toString();
                        Log.d("This is an element", Integer.toString(i)
                                + " --" + element);


                    }
                }

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @Override
    protected void onPostExecute(SoapObject result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        if (result != null) {
            String response_name = result.getName();

            TextView tv = (TextView) findViewById(R.id.textView5);
            tv.setText(result.getProperty(0).toString());
        }

        else {

            Toast.makeText(getApplicationContext(), "No Response",
                    Toast.LENGTH_LONG).show();

        } 
    }
}

}");

The webservice method i am calling retuns a complexType Object called GramaNiladhari. It consists of 5 string types. When I run this code I get the following SoapObject result.

anyType{gnName=anyType{}; address=anyType{}; workingDays=anyType{}; gnDivision=anyType{}; contactNumber=anyType{}; }

But here i am missing the values,and they are replaced with anyType{} . How can I retrieve the real values ?

Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
calling webservices that return complexTypes in android using ksoap2
calling webservices that return complexTypes in android using ksoap2   Can anyone direct me to a site or show me an example ,on how to call a webservice which returns a complexType as the result, in an android app
calling webservices that return complexTypes in android using ksoap2
calling webservices that return complexTypes in android using ksoap2   Here's my code for android application,to call aweb service method and return..._niladhari, menu); return true; } private class SupportThread extends
Advertisements
webservices in websphere server using eclipse
webservices in websphere server using eclipse  can websphere server used instead of tomcat??...if so any changes to be made? Please elaborate
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello... page when user clicks on a button i am calling a javascript function(eg myFunc... task.now i want this servlet(myServlet) to return a url(eg. pages/file.jsp
Tictactoe game-2 players- using jax webservices & jsp
Tictactoe game-2 players- using jax webservices & jsp  Hi all, Could anyone please suggest the code /post source code of tictactoe game for 2 players with x & 0 as markers and use mysql database to persist the moves
webservices
webservices  can any one tell me how to develop and execute ---------- j2ee webservices example in weblogic server with (netbeans or eclipse
Webservices
Webservices  Hi, this is chinna, i am trying to develop a web service that has to return one table data. i have taken table data in a two dimensional...] + "DES" + projects[i][1]); } return projects
calling a session bean bean from servlet using netbeans - EJB
calling a session bean from servlet using netbeans  How to call a session bean from servlet using netbeans in Java
WebServices In Java
WebServices In Java  Sample Example with screen shots using eclipse in java.it contain lower level to higher level example
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI ... objects for these classes and how can we call these functions by using JNI. Am using myeclipse Please help me in resolving this problem. It?s urgent
Webservices - WebSevices
Webservices  Hi All, Can anybody send me the sample application for developing webservices using axis2 with Eclipse Plugin. Thanks. regards anwar
webservices - WebSevices
webservices i find that there are number of ways to develop webservices which one is good... me one simple webservice application using axis2 as soon as possible. Thanks.... http://www.roseindia.net/webservices/web-services-development.shtml Thanks
webservices in java
webservices in java  what is the real time use of webservices in java
Calling Methods Using SpEL
Calling Methods Using SpEL Spring 3 provides powerful Expression Language which can be used to wire values into beans properties by calling method of any... by calling methods. Person.java: The Person class contains property named "
webservices - WebSevices
webservices  i want a sample on webservices which can help me to build a custom webservice project using GlassFish 2 ? NetBeans 6.1 ? SSH... reservation using webservises
WebServices In Java
WebServices In Java  Need Web Services Examples in eclipse. Regards, Sathya
Non SOAP webservices - WebSevices
webservices in WebLogic? i believe we can do using REST however is there any other option other than REST to implement non-soap webservices? Do we have WSDL incase of non-soap webservices
how to start intergrated webcam of a laptop without calling its exe file using java only - Java Beginners
how to start intergrated webcam of a laptop without calling its exe file using java only  how to open integrated webcam of a laptop without calling its exe file using java only?.simply what i am asking is that is there any method
webservices security
webservices security  am doing project in web services security. can one sugesst me a best application for web service
calling java method from html form with out using javascript - JSP-Servlet
calling java method from html form with out using javascript  How can... isNumberString(InString){ if(InString.length==0) return (false); var RefString... (TempChar, 0)==-1) return (false); } return (true);}<
Calling Static Methods Using SpEL
Calling Static Method Using SpEL Spring 3 provides powerful Expression Language which can be used to wire values into beans properties by calling static method of any bean using SpEL's T() operator. Lets take an example
Android using database
Android using database  How to Add,delete,modify the contact name,address,phone no into the database using android coding
WebServices In JAVA
WebServices In JAVA  need sample example for webservice in java platform(web application)   Hi, Please check Web Services Examples in NetBeans. Thanks
What is webservices?
What is webservices?  What is web-services and what are the different types of web-services? It would be great if someone explain me the difference between these types of web-services in Java
video calling
video calling  how to implement video calling using java? i am a final year mca student please give me some samplecodes
video calling
video calling  how to implement video calling using java? i am a final year mca student please give me some samplecodes
Webservices - WebSevices
Webservices  Hi, I have a problem in webservices. I have defined a service which shoud read the xml file from the clientside and read the values... for more information. http://www.roseindia.net/webservices/wsddfileforejb
WebServices deployment in Weblogic - WebSevices
WebServices deployment in Weblogic  Hi, I want to create a service using Axis2 and deploy the service in Weblogic, along with my application war file. What is the common practice? Thanks in Advance, VJ
Webservices with attachment on websphere - WebSevices
Webservices with attachment on websphere  Need some help urgently!!! I need to provide an interface with webservices to access one of our services...). 2. Have some one some example ready for attachment with webservices
What is SOA and Webservices?
What is SOA and Webservices?  Hi, I want to learn SOA and Webservices. Can anyone tell me What is SOA and Webservices? Thanks   Hello, Check the tutorial: SOA and Web Services Thanks