I'm building my first application in android which consumes a wcf service.I'm using ksoap2 to parse the response.The response is actually an array of objects defined in C#.I did this following this really helpful guide.Now my problem is that I need to consume a wcf service which returns again an array of objects in C# but this time some properties of these objects are other objects.So my question is how can I map the inner objects so that i can parse their properties?
In case I was unclear, I need to parse an object like this:
public class OutterObject {
private InnerObject1 io1;
private InnerObject2 io2;
}
Hope I was clear enough
Ok this is my simplified code i can't post all of it just the portion i think is at fault
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("connString",args.get(0));
Request.addProperty("ClCode", args.get(1));
Request.addProperty("TeCode", args.get(2));
Request.addProperty("CourseDate", args.get(3));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(namespace, "SRV_WeekProgramm",newSRV_WeekProgramm().getClass());
envelope.addMapping(namespace, "Course", new Course().getClass());
envelope.addMapping(namespace, "StudentHours", new StudentHours().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Course response = (Course)envelope.bodyIn; //this is where it crashes
and this is the thrown exception: java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to connectionInitializer.Course
Here is an example that worked for me.
This is response message type from web service
The method
loginUser
definitionClass
UserResponse
(Outter) containsUser
property:And the
User
class (Inner)This is important: make sure you register the keys for both outter class and inner class.
Finally, you can get the result by casting:
Hope this help!