Hi,
I met a problem while learning to us Ksoap2 on Android system. And I
am seeking for help.
The problem is I want to parse the response of webservice directly
into java object. I find that code on this rul:
http://code.google.com/
p/ksoap2-android/wiki/CodingTipsAndTricks#sending/
receiving_array_of_complex_types_or_primitives
But it never works. Could you help me for this? I have pending on this
problem for 2 weeks. Thank you.
Here is the android object - testObject1
public class testObject1 implements KvmSerializable {
public String testName1;
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
return testName1;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 1;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo
arg2) {
// TODO Auto-generated method stub
arg2.name = "testName1";
arg2.type = PropertyInfo.STRING_CLASS;
}
@Override
public void setProperty(int arg0, Object arg1) {
// TODO Auto-generated method stub
testName1 = arg1.toString();
}
}
Webservice calling code:
SoapObject soapObject = new SoapObject(NAMESPACE, METHOD);
SoapSerializationEnvelope soapEnvelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.bodyOut = soapObject;
soapEnvelope.setOutputSoapObject(soapObject);
soapEnvelope.addMapping(NAMESPACE, "testObject1",
testObject1.class);
HttpTransportSE httpTransportSE = new
HttpTransportSE(WEBSERVICEURL);
httpTransportSE.debug = true;
try {
httpTransportSE.call(SOAPACTION, soapEnvelope);
testObject1 soapResponse = (testObject1) soapEnvelope.bodyIn;//Here
is the error java.lang.ClassCastException:
org.ksoap2.serialization.SoapObject
} catch (Exception e) {
e.printStackTrace();
}
Webservice method
public testObject1 HelloWorld()
{
testObject1 obj = new testObject1();
obj.testName1 = "return";
return obj;
}
Webservice response xml
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorldResponse xmlns="
http://tempuri.org/">
<HelloWorldResult>
<testName1>string</testName1>
</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>