I have spent several days trying to figure out how can I make my user defined java class serializable, so that i can send it as a parameter in android ksoap call to c# web method . Below is my code and the exceptions thrown in logcat when calling the webservice , I would be thankful if i get an immediate answer or help .
My java class XY.java
:
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class XY implements KvmSerializable {
public static Class XY_CLASS = XY.class;
private String MyNum;
private String OppPhoneNum;
private String Name;
public XY()
{
}
public XY(String MyNum, String Name, String oppNum)
{
this.MyNum = MyNum;
this.Name = Name;
this.OppPhoneNum = oppNum;
}
public String getPhoneNum() {
return MyNum;
}
public void setPhoneNum(String MyNum) {
this.MyNum = MyNum;
}
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getOpponentPhoneNum() {
return OppPhoneNum;
}
public void setOpponentPhoneNum(String OppPhoneNum) {
this.OppPhoneNum = OppPhoneNum;
}
@Override
public Object getProperty(int arg0) {
switch(arg0)
{
case 0:
return MyNum;
case 1:
return OppPhoneNum;
case 2:
return Name;
}
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 3;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "MyNum";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "OppPhoneNum";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Name";
break;
default:break;
}
}
@Override
public void setProperty(int index, Object value) {
switch(index)
{
case 0:
MyNum = value.toString();
break;
case 1:
OppPhoneNum = value.toString();
break;
case 2:
Name = value.toString();
break;
default:
break;
}
}
}
C# equivalent class:
[Serializable]
public class XY
{
public System.String Name
{
get;
set;
}
public System.String MyNum
{
get;
set;
}
public System.String OppPhoneNum
{
get;
set;
}
}
And this is how i am calling the service using ksoap from my activity:
private void unKnown(List<XY> entries)
{
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo entriesProp =new PropertyInfo();
entriesProp.setName("entries");
entriesProp.setValue(entries);
entriesProp.setType(ArrayList.class);
//Use this to add parameters
request.addProperty(entriesProp);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "XY", XY.XY_CLASS);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ADDCONTACTS, envelope);
// Get the SoapResult from the envelope body.
if (envelope.bodyIn instanceof SoapFault)
{
String str= ((SoapFault) envelope.bodyIn).faultstring;
Log.i("", str);
}
else
{
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
if(resultsRequestSOAP != null)
{
Log.i("AddContacts", "Adding Contacts succeeded");
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}**
Logcat Exception :
java.lang.RuntimeException: Cannot Serialize: [XY .....**
Note : i am trying to pass list of XY objects as parameter to the web service method . I would appreciate any help .