Android + Ksoap: object with array of complex type

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Android + Ksoap: object with array of complex type

Postby poohley » Wed Aug 25, 2010 12:34 pm

Hello,

My Android application call my C# .Net Webservice Method. I want to pass a complex object with name "WSCompany". To receive this kind of object via WebService on Android is no problem (only to send).

This is my .Net WebService Method.

[SoapRpcMethod]
[WebMethod]
public int TransferCompany(WSCompany company)
{
....
}

I have created an Object (WSCompany) that implements KvmSerializable. But if I try to pass my created object via webservice than i receive this exception:

java.lang.RuntimeException: Cannot serialize: [Lde.reinhardt.software.system5.webservice.objects.WSPerson;@43c047b0


This is my code to call my webservice:

String METHOD_NAME = "TransferCompany1";
SoapObject request_ = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelope_ =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope_.dotNet = false;
soapEnvelope_.setOutputSoapObject(request_);

WSCompany thisCompany = new WSCompany();
thisCompany.setName("Company A");

WSPerson[] personen_ = new WSPerson[1];
personen_[0] = new WSPerson();
personen_[0].setName("Person");

thisCompany.setPersonen(personen_);

PropertyInfo pi = new PropertyInfo();
pi.setName("company");
pi.setValue(thisCompany);
pi.setType(WSCompany.EVENT_CLASS);
request_.addProperty(pi);

soapEnvelope_.addMapping(WSBaseObject.NAMESPACE,WSPerson.NAME,
new WSPerson().EVENT_CLASS);

soapEnvelope_.addMapping(WSBaseObject.NAMESPACE,WSCompany.NAME,
new WSCompany().EVENT_CLASS);

Log.v("RS",callByAndroidHttpTransport(NAMESPACE, MYWEBSERVICEURL, METHOD_NAME, soapEnvelope_));



The structure of object (WebService):

[Serializable()]
public class WSCompany
{
private String name = String.Empty;
private WSPerson[] personen = new WSPerson[0];

public WSPerson[] Personen
{
get { return personen; }
set { personen = value;}
}

public String Name
{
get { return name; }
set { name = value; }
}
}

[Serializable()]
public class WSPerson
{
private String name = String.Empty;

public String Name
{
get { return name; }
set { name = value; }
}
}


If I remove the WSPerson attributes of both sides (Android & WebService) it works fine. I have try to use an vector instead an array but it does not work.

Can anyone help me or give me an example that works? I hope you understand my problem. Sorry but my english is not so good.


Best regards

Christian
Hamburg/Germany
poohley
Freshman
Freshman
 
Posts: 2
Joined: Wed Aug 25, 2010 12:27 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Google [Bot] and 5 guests