[ksoap2-android] How to send a Complext type Array

4,106 views
Skip to first unread message

Euber (Malk)

unread,
May 25, 2011, 10:57:51 PM5/25/11
to ksoap2-android
I wanna send a array of objects
I search in web but dont see examples using ksoap2 and array of
complex type.

i tried many ways like manually or using marsh.... But not sucess.

i wanna sent a xml like this
<users>
<user>
<name>Jonh</name>
<age>12</age>
</user>
<user>
<name>Marie</name>
<age>27</age>
</user>
</users>

sef

unread,
May 26, 2011, 5:20:01 AM5/26/11
to ksoap2-android
try if this one will help you
http://people.unica.it/bart/ksoap2-patch/

i'm trying to send array of int with this patch version but cant
success yet

Manfred Moser

unread,
May 26, 2011, 12:32:31 PM5/26/11
to ksoap2-...@googlegroups.com
Please keep in mind that this patch has not made it into the project
because it does not even compile when applied so you might have
limited success with it.

Euber (Malk)

unread,
May 26, 2011, 2:21:59 PM5/26/11
to ksoap2-android
Lol?
the default ksoap2 cant send a array of objets?

Manfred Moser

unread,
May 26, 2011, 3:56:17 PM5/26/11
to ksoap2-...@googlegroups.com
Yes it can just fine. You just have to do it your self in a Marshaller
or build up the SoapObject hierarchy on the fly.
The patch is a convenience implementation that does however not work
with Java 1.3 as required by the ksoap build.

The contributors never came forward with an improved patch and I dont
have the time to do it.

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

Feel free to improve the patch and get it to work and I will pull it
in and cut another release.

manfred

Euber (Malk)

unread,
May 26, 2011, 9:21:33 PM5/26/11
to ksoap2-android
I code using Marshaller and send a single object with sucess.
I can send a object "user", but when i wanna send a user[] or a object
users with a list of user the ksoap cant serialize my objects.
This is my problem.
I make a Property Info with user and add to Envelope. How i can add
this Property info to another property?
This is my first idea, but dont work.

Propertyinfo pi = new Propertyinfo();
pi.setName("user");
pi.setValuer(user);

Propertyinfo pi2 = new Propertyinfo();
pi2.setName("users");
pi2.setValuer(pi);







On 26 maio, 16:56, Manfred Moser <mosa...@gmail.com> wrote:
> Yes it can just fine. You just have to do it your self in a Marshaller
> or build up the SoapObject hierarchy on the fly.
> The patch is a convenience implementation that does however not work
> with Java 1.3 as required by the ksoap build.
>
> The contributors never came forward with an improved patch and I dont
> have the time to do it.
>
> More details are athttp://code.google.com/p/ksoap2-android/issues/detail?id=19

Andrew Oppenlander

unread,
May 26, 2011, 9:47:41 PM5/26/11
to ksoap2-...@googlegroups.com
I had a working patch that let you add SoapObjects to SoapObjects, which would allow you to generate the soap xml you want, but I don't think I was allowed to post it because it was work for a closed source project.

The additions are:
  1. Method addSoapObject in SoapObject.java, which adds SoapObjects to the properties array
  2. Recursive method in SoapSerializationEnvelope.java that adds the ability to write the layered SoapObjects
It's been several months since I wrote this, but I can try reworking it tonight/this weekend.
--
Andrew Oppenlander
Computer Science and Pure Mathematics
University of Cincinnati
Mobile: 740-816-2357

Andrew Oppenlander

unread,
May 27, 2011, 1:19:37 AM5/27/11
to ksoap2-...@googlegroups.com
I've finished the patch, which is forked from the latest version. You can download the jar here.
Or you can build it yourself from my github.

To get this xml:
<users>
  <user>
     <name>Jonh</name>
     <age>12</age>
  </user>
  <user>
     <name>Marie</name>
     <age>27</age>
  </user>
</users>

You would do this:
SoapObject users = new SoapObject(NAMESPACE, "users");
SoapObject john = new SoapObject(NAMESPACE, "user");
john.addProperty("name", "john");
john.addProperty("age", 12);
SoapObject marie = new SoapObject(NAMESPACE, "user");
john.addProperty("name", "marie");
john.addProperty("age", 27);
users.addSoapObject(john);
users.addSoapObject(marie);

Let me know if you have any problems.

Currently adding a SoapObject will put it in a different vector than PropertyInfos.
When it constructs the request it will always write SoapObjects before PropertyInfos.
If you think I should change this, so the user can choose the order of SoapObjects/PropertyInfos let me know.
--
Andrew Oppenlander

Manfred Moser

unread,
May 27, 2011, 12:25:18 PM5/27/11
to ksoap2-...@googlegroups.com
Wow .. this is awesome. Thanks a lot. I will pull it in and if you are
interested I will create a 2.5.5 release..

manfred

On Thu, May 26, 2011 at 10:19 PM, Andrew Oppenlander

Manfred Moser

unread,
May 27, 2011, 12:43:03 PM5/27/11
to ksoap2-...@googlegroups.com
Ok. I have applied the patch and put the doc below onto the wiki at

http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks?ts=1306514452&updated=CodingTipsAndTricks

I am also contemplating closing issue
http://code.google.com/p/ksoap2-android/issues/detail?id=19

Would that be okay?

manfred

Euber (Malk)

unread,
Jun 4, 2011, 10:45:00 AM6/4/11
to ksoap2-android
i will test tomorrow and post the results here.


On 27 maio, 13:43, Manfred Moser <mosa...@gmail.com> wrote:
> Ok. I have applied the patch and put the doc below onto the wiki at
>
> http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks?ts=1...
>
> I am also contemplating closing issuehttp://code.google.com/p/ksoap2-android/issues/detail?id=19
Message has been deleted

DoM

unread,
Jun 6, 2011, 6:30:25 AM6/6/11
to ksoap2-android

I've a ws how must receive this:
<InserisciTransazione xmlns="http://tempuri.org/">
<bussInfo>
<Codice>string</Codice>
<Login>string</Login>
<Password>string</Password>
<Id>int</Id>
<IdUtente>int</IdUtente>
</bussInfo>
<codiceCarta>string</codiceCarta>
<importo>string</importo>
<prodotti>
<ProdottoConcorsoTransazionePunti>
<ID_Transazione>int</ID_Transazione>
<ID_ProdottoConcorso>int</ID_ProdottoConcorso>
<QuantitaAcquistata>double</QuantitaAcquistata>
</ProdottoConcorsoTransazionePunti>
<ProdottoConcorsoTransazionePunti>
<ID_Transazione>int</ID_Transazione>
<ID_ProdottoConcorso>int</ID_ProdottoConcorso>
<QuantitaAcquistata>double</QuantitaAcquistata>
</ProdottoConcorsoTransazionePunti>
</prodotti>
</InserisciTransazione>
I'm able to pass bussInfo codiceCarta and importo,the problem is to
pass ProdottoConcorsoTransazionePunti[] prodotti,this is my code :

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("bussInfo", bussInfo);
request.addProperty("codiceCarta",num_carta);
request.addProperty("importo",imp);
  SoapObject product = new SoapObject (NAMESPACE,"prodotti");
  SoapObject prod = new
SoapObject(NAMESPACE,"ProdottoConcorsoTransazionePunti");
  prod.addProperty("ID_ProdottoConcorsoTransazione",
prodotti[0].getID_Prodotto());
  prod.addProperty("QuantitaAcquistata",
prodotti[0].getQuantitaAcquistata());
  product.addSoapObject(prod);
request.addProperty(product);

but it doesn't work for me.Is there any error?

Andrew Oppenlander

unread,
Jun 6, 2011, 10:53:04 AM6/6/11
to ksoap2-...@googlegroups.com

Its likely your error is from marshelling a double.
You should turn on debugging and figure out what exactly your error is.

DoM

unread,
Jun 7, 2011, 4:40:45 AM6/7/11
to ksoap2-android
It wasn't the double,but the array,i solved :

SoapObject prodotti = new SoapObject
(NAMESPACE,"ListaProdotti");
SoapObject ProdottoConcorsoTransazionePunti = new
SoapObject(NAMESPACE,"ProdottoConcorsoTransazionePunti");

ProdottoConcorsoTransazionePunti.addProperty("ID_ProdottoConcorsoTransazione",
ListaProdotti[0].getID_Prodotto());

ProdottoConcorsoTransazionePunti.addProperty("QuantitaAcquistata",
ListaProdotti[0].getQuantitaAcquistata());

prodotti.addProperty("ProdottoConcorsoTransazionePunti",ProdottoConcorsoTransazionePunti);

SoapObject ProdottoConcorsoTransazionePunti1 = new
SoapObject(NAMESPACE,"ProdottoConcorsoTransazionePunti");

ProdottoConcorsoTransazionePunti1.addProperty("ID_ProdottoConcorsoTransazione",
ListaProdotti[1].getID_Prodotto());

ProdottoConcorsoTransazionePunti1.addProperty("QuantitaAcquistata",
ListaProdotti[1].getQuantitaAcquistata());

prodotti.addProperty("ProdottoConcorsoTransazionePunti",ProdottoConcorsoTransazionePunti1);
request.addProperty("prodotti", prodotti);

On 6 Giu, 16:53, Andrew Oppenlander <andrew.oppenlan...@gmail.com>
wrote:
> Its likely your error is from marshelling a double.
> You should turn on debugging and figure out what exactly your error is.

Manfred Moser

unread,
Jun 7, 2011, 10:35:12 AM6/7/11
to ksoap2-...@googlegroups.com
In the future you should probably just loop through the array and add the properties in the e.g for loop.

manfred

Euber (Malk)

unread,
Jun 22, 2011, 9:15:23 AM6/22/11
to ksoap2-android
Work perfect to me.
Thanks.



On 7 jun, 11:35, Manfred Moser <mosa...@gmail.com> wrote:
> In the future you should probably just loop through the array and add the
> properties in the e.g for loop.
>
> manfred
>
>
>
> On Tue, Jun 7, 2011 at 1:40 AM, DoM <daume...@gmail.com> wrote:
> > It wasn't the double,but the array,i solved :
>
> >       SoapObject prodotti = new SoapObject
> > (NAMESPACE,"ListaProdotti");
> >       SoapObject ProdottoConcorsoTransazionePunti = new
> > SoapObject(NAMESPACE,"ProdottoConcorsoTransazionePunti");
>
> > ProdottoConcorsoTransazionePunti.addProperty("ID_ProdottoConcorsoTransazion­e",
> > ListaProdotti[0].getID_Prodotto());
>
> > ProdottoConcorsoTransazionePunti.addProperty("QuantitaAcquistata",
> > ListaProdotti[0].getQuantitaAcquistata());
>
> > prodotti.addProperty("ProdottoConcorsoTransazionePunti",ProdottoConcorsoTra­nsazionePunti);
>
> >       SoapObject ProdottoConcorsoTransazionePunti1 = new
> > SoapObject(NAMESPACE,"ProdottoConcorsoTransazionePunti");
>
> > ProdottoConcorsoTransazionePunti1.addProperty("ID_ProdottoConcorsoTransazio­ne",
> > ListaProdotti[1].getID_Prodotto());
>
> > ProdottoConcorsoTransazionePunti1.addProperty("QuantitaAcquistata",
> > ListaProdotti[1].getQuantitaAcquistata());
>
> > prodotti.addProperty("ProdottoConcorsoTransazionePunti",ProdottoConcorsoTra­nsazionePunti1);
Reply all
Reply to author
Forward
0 new messages