Android: Calling Web Service with complex types

Friday, 8 October 2010 08:39 by Anupama

Calling web service on Android is possible with KSOAP2 (ksoap2-android-assembly-2.4-jar-with-dependencies.jar)  or you can write you own soap message formatter and can make http call using android apache http classes.

In this post i am going to explain calling web service using ksoap lib for dotnet service. This web service is hosted at http://bimbim.in/Sample/TestService.asmx. You can use this for your reference because Android emulator is not connecting with local web development server which comes with Visual Studio ( i don’t know exact reason).

 

For complete understanding i will suggest you to download complete android code from here 

Bimbimin.Android.Webservice.Client.rar (177.05 kb) and debug it using my web service URL.

 

First i will brief web service which i will use to explain web service calling.

I have created one serializable class Person with 4 attributes of different types in asp.net

[Serializable]
public class Person
{
    private string _name = string.Empty;
    private int _age = 0;
    private float _salary = 100000.0f;
    private DateTime? _dob = new DateTime(1980, 01, 15);
 
    public float Salary
    {
        get { return _salary; }
        set { _salary = value; }
    }
    public DateTime? Dob
    {
        get { return _dob; }
        set { _dob = value; }
    }
 
    public int Age
    {
        get { return _age; }
        set { _age = value; }
    }
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
}

and create two web method in web service GetSingle and SetValue.

public class TestService : System.Web.Services.WebService
{
 
    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
 
    [WebMethod]
    public Person GetSingle()
    {
        Person person = new Person();
        person.Name = "bimbim.in";
        person.Age = 30;
        person.Dob = new DateTime(1980, 01, 15);
        person.Salary = 50000f;
 
        return person;
    }
 
    [WebMethod]
    public bool SetValue(Person value)
    {
        bool result = false;
        if (value != null)
        {
            result = true; 
        }
 
        return result;
    }
}

One takes Person as input parameter and other return Person object.

You can see wsdl for web service by http://bimbim.in/Sample/TestService.asmx?wsdl or just by using http://bimbim.in/Sample/TestService.asmx in browser you can see method list and by clicking method name you can see all details of that method.

Now i will explain how to call this web service method in Android using Ksoap 2. Although this lib has some bug and limitation but it is very useful.

In android application first we have to create a java class for Web service Person structure and we have to implement KvmSerializable interface in this class. KvmSerializable is used to transform soap message by ksoap library.

/**
 * 
 */
package bimbimin.android.webservice.dto;
 
import java.util.Date;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
 
/**
 * @author Bimbim
 * 
 */
public class Person implements KvmSerializable
{
    public static Class PERSON_CLASS = Person.class;
    private String _name = "";
    private int _age = 0;
    private float _salary = 100000.0f;
    private Date _dob = new Date(1980, 01, 15);
 
    public Person()
    {
    }
 
    public Person(SoapObject obj)
    {
        this._name = obj.getProperty("Name").toString();
        this._age = Integer.parseInt(obj.getProperty("Age").toString());
        this._salary = Float.parseFloat(obj.getProperty("Salary").toString());
 
        String dob = obj.getProperty("Dob").toString();
        // Change date string according to your local
        String[] parts = dob.split("T")[0].split("-");
        this._dob = new Date(Date.UTC(Integer.parseInt(parts[0]), Integer
                .parseInt(parts[1]), Integer.parseInt(parts[2]), 0, 0, 0));
    }
 
    /**
     * @return the _name
     */
    public String get_name()
    {
        return _name;
    }
 
    /**
     * @param name
     *            the _name to set
     */
    public void set_name(String name)
    {
        _name = name;
    }
 
    /**
     * @return the _age
     */
    public int get_age()
    {
        return _age;
    }
 
    /**
     * @param age
     *            the _age to set
     */
    public void set_age(int age)
    {
        _age = age;
    }
 
    /**
     * @return the _salary
     */
    public float get_salary()
    {
        return _salary;
    }
 
    /**
     * @param salary
     *            the _salary to set
     */
    public void set_salary(float salary)
    {
        _salary = salary;
    }
 
    /**
     * @return the _dob
     */
    public Date get_dob()
    {
        return _dob;
    }
 
    /**
     * @param dob
     *            the _dob to set
     */
    public void set_dob(Date dob)
    {
        _dob = dob;
    }
 
    /* (non-Javadoc)
     * @see org.ksoap2.serialization.KvmSerializable#getProperty(int)
     */
    @Override
    public Object getProperty(int index)
    {
        Object object = null;
        switch (index)
        {
        case 0:
        {
            object = this._name;
            break;
        }
        case 1:
        {
            object = this._age;
            break;
        }
        case 2:
        {
            object = this._salary;
            break;
        }
        case 3:
        {
            object = this._dob;
            break;
        }
        }
        return object;
    }
 
    /* (non-Javadoc)
     * @see org.ksoap2.serialization.KvmSerializable#getPropertyCount()
     */
    @Override
    public int getPropertyCount()
    {
        // TODO Auto-generated method stub
        return 4;
    }
 
    /* (non-Javadoc)
     * @see org.ksoap2.serialization.KvmSerializable#
     * getPropertyInfo(int, java.util.Hashtable, 
     * org.ksoap2.serialization.PropertyInfo)
     */
    @Override
    public void getPropertyInfo(int index, Hashtable arg1,
            PropertyInfo propertyInfo)
    {
        // TODO Auto-generated method stub
        switch (index)
        {
        case 0:
        {
            propertyInfo.name = "Name";
            propertyInfo.type = PropertyInfo.STRING_CLASS;
            break;
        }
        case 1:
        {
            propertyInfo.name = "Age";
            propertyInfo.type = PropertyInfo.INTEGER_CLASS;
            break;
        }
        case 2:
        {
            propertyInfo.name = "Salary";
            propertyInfo.type = Float.class;
            break;
        }
        case 3:
        {
            propertyInfo.name = "Dob";
            propertyInfo.type = Date.class;
            break;
        }
        }
    }
 
    /* (non-Javadoc)
     * @see org.ksoap2.serialization.KvmSerializable#setProperty
     * (int, java.lang.Object)
     */
    @Override
    public void setProperty(int index, Object obj)
    {
        // TODO Auto-generated method stub
        switch (index)
        {
        case 0:
        {
            this._name = obj.toString();
            break;
        }
        case 1:
        {
            this._age = Integer.parseInt(obj.toString());
            break;
        }
        case 2:
        {
            this._salary = Float.parseFloat(obj.toString());
            break;
        }
        case 3:
        {
            this._dob = new Date(Date.parse(obj.toString()));
            break;
        }
        }
    }
 
}

I have created four attributes in this class as web service class and Implemented KvmSerializable 4 methods.

  1. public int getPropertyCount(): return attribute count in our case it is 4.
  2. public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo propertyInfo): Set propertyInfo attribute name and type, see above code listing.
  3. public Object getProperty(int index): Called by ksoap when formatting soap message.
  4. public void setProperty(int index, Object obj): Called by ksoap when created instance of classes from soap message response.

Note: Please used same sequence while writing these method as you have used in getPropertyInfo method.

Now make call using ksoap library

 
package bimbimin.android.webservice.client;
 
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.MarshalDate;
import org.ksoap2.serialization.MarshalFloat;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import bimbimin.android.webservice.dto.Person;
 
public class ServiceCall
{
    private static final String SOAP_ACTION = 
        "http://tempuri.org/";
    private static final String NAMESPACE = 
        "http://tempuri.org/";
    private static final String URL = 
        "http://bimbim.in/Sample/TestService.asmx";
 
    private boolean isResultVector = false;
 
    protected Object call(String soapAction, 
            SoapSerializationEnvelope envelope)
    {
        Object result = null;
        
        final HttpTransportSE transportSE = new HttpTransportSE(URL);
        
        transportSE.debug = false;
 
        // call and Parse Result.
        try
        {
            transportSE.call(soapAction, envelope);
            if (!isResultVector)
            {
                result = envelope.getResponse();
            } else
            {
                result = envelope.bodyIn;
            }
        } catch (final IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (final XmlPullParserException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (final Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }
 
    public Person CallGetSingle()
    {
        final String sGetSingle = "GetSingle";
 
        // Create the outgoing message
        final SoapObject requestObject = 
            new SoapObject(NAMESPACE, sGetSingle);
        // Create soap envelop .use version 1.1 of soap
        final SoapSerializationEnvelope envelope = 
            new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        // add the outgoing object as the request
        envelope.setOutputSoapObject(requestObject);
        envelope.addMapping(NAMESPACE, 
                Person.PERSON_CLASS.getSimpleName(),
                Person.PERSON_CLASS);
 
        // call and Parse Result.
        final Object response = this.call(
                SOAP_ACTION + sGetSingle, envelope);
        Person result = null;
        if (response != null)
        {
            result = new Person((SoapObject) response);
        }
 
        return result;
    }
 
    public Boolean CallSetValue(Person param)
    {
        final String sSetValue = "SetValue";
        final String svalue = "value";
        // Create the outgoing message
        final SoapObject requestObject = 
            new SoapObject(NAMESPACE, sSetValue);
        // Set Parameter type String
        requestObject.addProperty(svalue, param);
        // Create soap envelop .use version 1.1 of soap
        final SoapSerializationEnvelope envelope = 
            new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        // add the outgoing object as the request
        envelope.setOutputSoapObject(requestObject);
        envelope.addMapping(NAMESPACE, 
                Person.PERSON_CLASS.getSimpleName(),
                Person.PERSON_CLASS);
        // Register Marshaler
        // For date marshaling
        Marshal dateMarshal = new MarshalDate();
        dateMarshal.register(envelope);
        // For float marshaling
        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(envelope);
        // call and Parse Result.
        final Object response = this.call(
                SOAP_ACTION + sSetValue, envelope);
        Boolean result = null;
        if (response != null)
        {
            try
            {
                if (response != null
                        && response.getClass() == 
                            org.ksoap2.serialization.SoapPrimitive.class)
                {
                    result = Boolean.parseBoolean(response.toString());
                }
            } catch (Exception e)
            {
                // TODO: handle exception
                e.printStackTrace();
            }
        }
 
        return result;
    }
}

 

To call web service with ksoap you have to first create SoapSerializationEnvelope envelope. add soap request SoapObject , add class mapping and add type marshalar which are not given in PropertyInfo class.

        // Create the outgoing message
        final SoapObject requestObject = 
            new SoapObject(NAMESPACE, sSetValue);
        // Set Parameter type String
        requestObject.addProperty(svalue, param);
        // Create soap envelop .use version 1.1 of soap
        final SoapSerializationEnvelope envelope = 
            new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        // add the outgoing object as the request
        envelope.setOutputSoapObject(requestObject);
        envelope.addMapping(NAMESPACE, 
                Person.PERSON_CLASS.getSimpleName(),
                Person.PERSON_CLASS);
        // Register Marshaler
        // For date marshaling
        Marshal dateMarshal = new MarshalDate();
        dateMarshal.register(envelope);
        // For float marshaling
        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(envelope);

 

and finally make http request using HttpTransportSE class

        final HttpTransportSE transportSE = new HttpTransportSE(URL);
        
        transportSE.debug = false;
 
        // call and Parse Result.
        try
        {
            transportSE.call(soapAction, envelope);
            if (!isResultVector)
            {
                result = envelope.getResponse();
            } else
            {
                result = envelope.bodyIn;
            }
        } catch (final IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

For complete understanding i will suggest you to download complete android code from here 

Bimbimin.Android.Webservice.Client.rar (177.05 kb) and debug it using my web service URL.

Comments

Comments (33) -

October 11. 2010 01:01

kishore

Hi Anupama, I am new to java and android dev. I tried your code but force close appears.

kishore

October 11. 2010 04:19

admin

I have verified this sample code it is working fine.
Please download project from bimbim.in/.../...min.Android.Webservice.Client.rar
and import it in your workspace and set Device API version is 8 (Android 2.2) in you project and solution and debug it. It will work.
Note: use ksoap lib "ksoap2-android-assembly-2.4-jar-with-dependencies.jar". You can download it from here ksoap2-android.googlecode.com/.../...endencies.jar

After this set break point in Main activity class and test it.

admin

October 28. 2010 20:41

retouche photos

...I... Come...
oooO................
(....)..... Oooo....
.\\..(.....(....)...
..\\_)..... )../....
.......... (_/......

____________________________________________________________________________
Leaving footprints, on behalf of your blog I've been here, read your article. Maybe your article is very exciting, maybe very bad, but it does not matter, because I do not understand the whole, the important thing is that I've been here , left a footprint here.'re free to help me little bit of the links below it.



retouche photos

October 29. 2010 02:53

vlad

Hello. I do not understand. how to see it works or not? I only see "Hello World, Main!"

vlad

October 29. 2010 02:54

vlad

Hello. I do not understand. how to see it works or not? I only see 'Hello World, Main!'

vlad

October 29. 2010 02:56

vlad

hello. i do not understand. how to see it works or not? I only see Hello World, Main

vlad

October 29. 2010 02:57

vladislav

hello. i do not understand. how to see it works or not? I only see Hello World, Main

vladislav

October 29. 2010 02:58

vladislav

hello. i do not understand. how to see it works or not? I only see Hello World, Main

vladislav

November 1. 2010 21:39

kishore

hai Anupama, thanks for u r response for my question. I am having one more problem how to send xml as request like, for authentication of user
<UserName>string</UserName>
<password>string</password>
<TokenId>318974764453</TokenId>.  can u plz explain me with an example.

kishore

November 9. 2010 04:28

admin

No this not correct method, can you tell me your method signature of AuthenticateUser like what parameter you are using?
It seems you are using parameter of type Credentials. In that case you have to create one class in android , please download my code and check that may be it will help you.

admin

December 8. 2010 20:32

Ravikanth

Hi ,

I am trying to run this example , But i am getting following Errors.

The method getProperty(int) of type Person must override a superclass method
The method getPropertyCount() of type Person must override a superclass method
The method getPropertyInfo(int, Hashtable, PropertyInfo) of type Person must override a superclass method
The method setProperty(int, Object) of type Person must override a superclass method

Can anybody help me in resolving these errors ? It would be of great help.

Thanks&Regards,
ravikanth

Ravikanth

December 9. 2010 00:52

admin

I have verified this sample code it is working fine.
Please download project from bimbim.in/.../...min.Android.Webservice.Client.rar
and import it in your workspace and set Device API version is 8 (Android 2.2) in you project and solution and debug it. It will work.
Note: use ksoap lib "ksoap2-android-assembly-2.4-jar-with-dependencies.jar". You can download it from here ksoap2-android.googlecode.com/.../...endencies.jar

After this set break point in Main activity class and test it.

admin

December 9. 2010 03:17

Ravikanth

Hi  Anupama ,

Thank you very much for your article.

It's compiling now when i have commented @Override.

I have downloaded your sample code and trying to run it on the Android Device.

But the application gets closed forcibly.I am testing on GPRS enebled phone.

Have you tested it on Emulator/Device ?

Do you know how to set internet configuration to android emulator ? I have internet to my PC but emulator is not recognising the connection.

Thanks&Regards,
Ravikanth

Ravikanth

December 9. 2010 03:24

Ravikanth

Hi ,

forgot to mention that i have written a small UI to display the elements of the class person.

Note : I am getting force close error even if have removed my code.

Thanks&Regards,
Ravikanth

Ravikanth

December 9. 2010 18:25

admin

Dear Ravikant,
First you check on internet connection on emulator by opening browser and go to google.com, it will open page if your pc is connected to internet.

To access internet from Your application you have to give permission in your application by changing "AndroidManifest.xml".

Put <uses-permission android:name="android.permission.INTERNET"></uses-permission> in "AndroidManifest.xml". Like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="bimbimin.android.webservice.client"
      android:versionCode="1"
      android:versionName="1.0">
      
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Main"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

</manifest>

admin

December 12. 2010 19:17

Ishwar

Hi anupama,
Thanks for such a nice article.. I was looking for it for almost 2 weeks.. You are the wo(MAN).

Ishwar

December 12. 2010 20:03

Ishwar

Hi anupama,
Thanks for such a nice article.. I was looking for it for almost 2 weeks.. You are the wo(MAN).

Ishwar

December 13. 2010 19:15

Ishwar

Hi can u please explain me how to send array from client to server.. i am sending class object to server in which one field is array of integers.. i am not able to send as the data assigned will always be null at server.. please explain as early as possible..

Thanks

Ishwar

January 4. 2011 07:01

Ilya

Hi ravikanth,

I fixed it ..."The method getProperty(int) of type Person must override a superclass method"... when set properties for project to java 1.6 (Properties->Java Compiler->Compiler compliance level: 1.6)

Ilya

January 25. 2011 12:28

Daniel

Hi Anupama,

Thank for your article. I have implemented a .net web service that returns an array of classes, similar to your Person class.

I have a problem when I pass a string in the request that is a filter of which records the web service should return. It's an ISO date (yyyymmdd).
I use request.addProperty( "changedAfter", "20110121" );

This all works fine in a .net client, but not in an Android client. It always gets the following error message:
'Server was unable to process request. ---> Object reference not set to an instance of an object.'

Unfortunatelly, I can not debug the web service when I have it running on the server to access it via Android. And I can't access get access the debugable web service that runs on my local machine when I start it out of Visual Studio.

Have you got an idea how to pass a string value as a request parameter? Or what else could be wrong?

I use the latest ksoap2 version 2.5.2 and Android 2.1.

Thanks
Daniel

Daniel

January 31. 2011 20:06

Mika

Hello. i do not understand. how to see it works or not? I only see Hello World, Main

Mika

February 2. 2011 01:58

admin

@Mika, You can debug application and see the result.

admin

February 3. 2011 02:34

Fabio

Hi,
thank you for your post!! I'm tring to customize you code but I have a problem.
I have a php/nusoap web service and this is the wsdl:


<definitions targetNamespace="http://localhost">

<types>

<xsd:schema elementFormDefault="qualified" targetNamespace="http://localhost">
<xsd:import namespace="schemas.xmlsoap.org/soap/encoding/"/>;
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>;

<xsd:complexType name="point">

<xsd:all>
<xsd:element name="id" type="xsd:int"/>
<xsd:element name="idUser" type="xsd:string"/>
<xsd:element name="type" type="xsd:int"/>
<xsd:element name="str1" type="xsd:float"/>
<xsd:element name="str2" type="xsd:float"/>
<xsd:element name="str3" type="xsd:float"/>
<xsd:element name="str4" type="xsd:float"/>
</xsd:all>
</xsd:complexType>

<xsd:complexType name="pointsArray">

<xsd:complexContent>

<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:point[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="status">

<xsd:all>
<xsd:element name="id" type="xsd:int"/>
<xsd:element name="idUser" type="xsd:string"/>
<xsd:element name="status" type="xsd:short"/>
<xsd:element name="desc" type="xsd:string"/>
<xsd:element name="dateTime" type="xsd:dateTime"/>
</xsd:all>
</xsd:complexType>

<xsd:complexType name="statusArray">

<xsd:complexContent>

<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:status[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="report">

<xsd:all>
<xsd:element name="point" type="tns:point"/>
<xsd:element name="statusArray" type="tns:statusArray"/>
</xsd:all>
</xsd:complexType>

<xsd:complexType name="setDataRequestType">

<xsd:all>
<xsd:element name="point" type="tns:point" form="unqualified"/>
</xsd:all>
</xsd:complexType>

<xsd:complexType name="setDataResponseType">

<xsd:all>
<xsd:element name="return" type="xsd:boolean" form="unqualified"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="setData" type="tns:setDataRequestType"/>
<xsd:element name="setDataResponse" type="tns:setDataResponseType"/>
</xsd:schema>
</types>

<message name="setDataRequest">
<part name="parameters" element="tns:setData"/>
</message>

<message name="setDataResponse">
<part name="parameters" element="tns:setDataResponse"/>
</message>

<message name="getMyDataRequest">
<part name="idUser" type="xsd:string"/>
</message>

<message name="getMyDataResponse">
<part name="pointsArray" type="tns:pointsArray"/>
</message>

<message name="getLocationDataRequest">
<part name="str1" type="xsd:float"/>
<part name="str2" type="xsd:float"/>
</message>

<message name="getLocationDataResponse">
<part name="pointsArray" type="tns:pointsArray"/>
</message>

<portType name="wsReportDataPortType">

<operation name="setData">
<documentation>Set data of a idUser</documentation>
<input message="tns:setDataRequest"/>
<output message="tns:setDataResponse"/>
</operation>

<operation name="getMyData">
<documentation>Get data of a idUser</documentation>
<input message="tns:getMyDataRequest"/>
<output message="tns:getMyDataResponse"/>
</operation>

<operation name="getLocationData">
<input message="tns:getLocationDataRequest"/>
<output message="tns:getLocationDataResponse"/>
</operation>
</portType>

<binding name="wsReportDataBinding" type="tns:wsReportDataPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>;

<operation name="setData">
<soap:operation soapAction="http://localhost/setData" style="document"/>

<input>
<soap:body use="literal" namespace="http://localhost"/>
</input>

<output>
<soap:body use="literal" namespace="http://localhost"/>
</output>
</operation>

<operation name="getMyData">
<soap:operation soapAction="http://localhost#getMyData" style="rpc"/>

<input>
<soap:body use="literal" namespace="http://localhost"/>
</input>

<output>
<soap:body use="literal" namespace="http://localhost"/>
</output>
</operation>

<operation name="getLocationData">
<soap:operation soapAction="http://localhost/Android/Server-side/streetReportServer/src/wsReportData.php/getLocationData" style="rpc"/>

<input>
<soap:body use="encoded" namespace="http://localhost" encodingStyle="schemas.xmlsoap.org/soap/encoding/"/>;
</input>

<output>
<soap:body use="encoded" namespace="http://localhost" encodingStyle="schemas.xmlsoap.org/soap/encoding/"/>;
</output>
</operation>
</binding>

<service name="wsReportData">

<port name="wsReportDataPort" binding="tns:wsReportDataBinding">
<soap:address location="http://localhost/Android/Server-side/streetReportServer/src/wsReportData.php"/>
</port>
</service>
</definitions>



This service works if I use SoapUI as Client and this is the xml request template:



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:loc="http://localhost" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:nam="NAMESPACE">
   <soapenv:Header/>
   <soapenv:Body>
      <loc:setData soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">;
         <point>
            <!--You may enter the following 7 items in any order-->
            <loc:id>?</loc:id>
            <loc:idUser>?</loc:idUser>
            <loc:type>?</loc:type>
            <loc:str1>?</loc:str1>
            <loc:str2>?</loc:str2>
            <loc:str3>?</loc:str3>
            <loc:str4>?</loc:str4>
         </point>
      </loc:setData>
   </soapenv:Body>
</soapenv:Envelope>



Debugging the Android application here is the request that it produce... I'm not an expert but it looks wery different from the SoapUi one and..the web service does't work in this case.

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"; xmlns:d="http://www.w3.org/2001/XMLSchema"; xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"; xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">;
<v:Header />
<v:Body>
<setData xmlns="http://10.0.2.2/"; id="o0" c:root="1">
<value i:type="n0Tongoint" xmlns:n0="http://10.0.2.2/">;
<id i:null="true" />
<idUser i:null="true" />
<type i:null="true" />
<str1 i:null="true" />
<str2 i:null="true" />
<str3 i:null="true" />
<str4 i:null="true" />
</value>
</setData>
</v:Body>
</v:Envelope>


And even if transportSE.call(soapAction, envelope); call public Object getProperty(int index), all tags are empty and transportSE.call(soapAction, envelope); got an exception.

Do you have any idea or suggestions?

Many thanks

Fabio

February 7. 2011 22:32

assem.mohsen




hello. i do not understand. how to see it works or not? I only see Hello World, Main

assem.mohsen

February 7. 2011 22:35

assem.mohsen

hello. i do not understand. how to see it works or not? I only see Hello World, Main

assem.mohsen

March 8. 2011 04:08

VIVIN JOY

Hi
  Thanks for posting such a good article.
   I am doing an Android project and and i am using the same method followed above for web Service calls, but find an error in one certain part.
It is that my object has two fields which are list of string and long. i can't serilaise that . pls tell me how to serialise a list pls

VIVIN JOY

March 16. 2011 04:03

chandan

hi anupma thx for gud post.

i have one query regarding i wanted to call web services in android for example i have login page i need to do authentication from web server and than move to home page. how it can be done can you please provide me sample code am using soap and need to parse json data format i dont have any idea about web service am new to this.

chandan

March 18. 2011 01:20

Ossama

Thank you very much

nice article !

Ossama

April 1. 2011 01:40

shivdatta

i followed your project...downloaded and ran but getting SocketException Operation timed out.

shivdatta

April 8. 2011 06:08

Ossama

Hello , your subject is so helpful.

But the webservice doesn't work.

The "out" object is null

Thank you.

thinking to corrige that

Ossama

April 22. 2011 22:09

Vaibhav Muley

I have run your code but i only saw Hello World,Main! please tell me if there is extra to do so in your code..

Vaibhav Muley

April 23. 2011 01:09

anupama

@Vaibhav
set break point in Main activity class and test it by debugging it.

anupama

June 24. 2011 00:00

Adam Winski

Great Article! I have a question, how to get collection from web service on android ? For example collection of users ?

Adam Winski