javaandroidweb-servicesksoap2android-ksoap2

Serialize an array of ints to send using KSOAP2


I'm having a problem trying to send an array of ints to a .NET web service which expects an array in one of the arguments. That's at least what I understand from the API description on the web service which says this:

<dataIndexIDs>
<int>int</int>
<int>int</int> </dataIndexIDs>

So when I send a single int like below I do not get any errors and I think it works fine.

request.addProperty("dataIndexIDs", 63);

But when I try to send an array of ints:

request.addProperty("dataIndexIDs", new int[] {63, 62}); // array of ints

or a ArrayList of Integers:

ArrayList<Integer> indexes = new ArrayList<Integer>();
    indexes.add(63);
    indexes.add(62);
    request.addProperty("dataIndexIDs", indexes); // ArrayList of Integers

I get thrown a "java.lang.RuntimeException: Cannot serialize" exception. Any help please? What am I doing wrong? Thanks!


Solution

  • It is a known issue with the KSOAP2 for Android library, which at the moment simply does not support arrays. The issue description is here:

    http://code.google.com/p/ksoap2-android/issues/detail?id=19

    A third-party patch, solution and an example can be found here:

    http://people.unica.it/bart/ksoap2-patch/

    I personally haven't tested any of them as they require also changing the web service WSDL but apparently they address the issue.