Returning Array of Primitive Types with KSOAP

KSOAP until recently had an issue with returning an array of primitive types. With the new patch the issue is solved. If you haven't downloaded the newest version of
KSOAP available on GitHub, you can use the following snippet:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope =
            new SoapSerializationEnvelope(SoapEnvelope.VER11);
            //envelope.dotNet = true;
            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);, envelope);

                KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
                for(int i=0;i<ks.getPropertyCount();i++)
                   ks.getProperty(i); //if complex type is present then you can cast this to SoapObject and if primitive type is returned you can use toString() to get actuall value.

This code was written by nebe.daredevil

If anyone else is having trouble to return array of primitive types with KSOAP, might consider the issue thread on Google Code

I hope the agony with KSOAP is near an end with this.


Valter said...

Your blog is helping me a lot. Took me out of a hole.


SeeSharpWriter said...

I am so glad I helped someone.

Anonymous said...

Thanks great blog you have help me lots, only one thing how to feed ks.getProperty(i); right into the SQLite on the device?

SeeSharpWriter said...

Perhaps you should write some code to insert the retrieved property into the SQLite database. I believe you should refer to some tutorial on working with SQLite and then combine the codes.

Rajan Thakrar said...

i am trying to call a web service (SOAP - .asmx web service [.net]) since last 2 to 3 days. I get the response but my problem is the response is neither JSON nor XML, so i didn't understand how can i parse my response string?

here i am putting my response string

Table=anyType{AdSpaceID=423; AdspaceName=Hoarding at football, (Amul); Address=football,(Amul)-Ahmedabad; };

Table=anyType{AdSpaceID=424; AdspaceName=Hoarding at football, tow. Bhulabhai.(Amul); Address=football, tow. Bhulabhai.(Amul)-Ahmedabad; };

Table=anyType{AdSpaceID=425; AdspaceName=Hoarding at Bhulabhai 4 Road Junction; Address=Bhulabhai 4 Road Junction-Ahmedabad; };

Table=anyType{AdSpaceID=426; AdspaceName=Hoarding at Bhulabhai Park, Tow. S.T. Stand; Address=Bhulabhai Park, Tow. S.T. Stand-Ahmedabad; }; }; }

above string is my response string and i want to
convert it into xml, so i can parse it...

Help me

Than you

Anonymous said...

hi seesharpwriter,
i followed your tutorial and it helped me a lot. thanks for that.
i am having an issue, i cannot access the array returned from my web service in android, i can access an individual data but not the array.
I am getting xmlpullparserexception expected Start tag error.

public class MainActivity extends Activity {

private final String NAMESPACE = "urn:hellowsdl";
private final String URL = ""; // WSDL URL
private final String SOAP_ACTION = "urn:hellowsdl#hello";
private final String METHOD_NAME = "hello"; // Method on web service

public void onCreate(Bundle savedInstanceState) {

if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()

Button btnSend = (Button) this.findViewById(;
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/*menu M=new menu();

PropertyInfo pi = new PropertyInfo();

TextView txtResult = (TextView) findViewById(;

EditText txtName = (EditText) findViewById(;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("strName", txtName.getText().toString());

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(

//envelope.addMapping(NAMESPACE, "menu",new menu().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
if (result != null) {

KvmSerializable ks = (menu)(KvmSerializable)envelope.bodyIn;
for(int i=0;i<ks.getPropertyCount();i++)

}} else {
"Web Service not Response!", Toast.LENGTH_LONG)

} catch (IOException e) {
// TODO Auto-generated catch block
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block



public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu);
return true;


could you please help me with that?
thanks ;)

Anonymous said...

I need to send some value data(i receive this data from one activity) to a webservice and receive 10elements, but the .call have an exeption

Geet choudhary said...

Hoarding advertising provides a boundless range of improvement as compared to other advertising mediums. The brand message conveyed through OOH media is also clutter-free.
Hoardings Agency across India

asha said...

Nice post
angularjs training in Bangalore

angularjs training institutes in Bangalore

best angularjs training in Bangalore

Twinkle said...

Nice post. It is really interesting. Thanks for sharing the post!
Domain Registrar In India, Check domain availability, Domain Transfer And Renewal In India, Website Creation Company In India, Web Design Company In India, Web Services, Web Design Company in Tuticorin

anusha said...

Full Stack Development Training in Chennai Searching for Full Stack Development training in chennai ? Bita Academy is the No 1 Training Institute in Chennai. Call for more details.

Post a Comment