Android ksoap nested soap objects in request gives error in response
- by Smalesy
I'm trying to do the following soap request on Android using KSOAP. It contains a list of nested soap objects. However, I must be doing something wrong as I get an error back.
The request I am trying to generate is as follows:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SetAttendanceMarks xmlns="http://hostname.net/">
<strSessionToken>string</strSessionToken>
<LessonMarks>
<Count>int</Count>
<LessonMarks>
<LessonMark>
<StudentId>int</StudentId>
<EventInstanceId>int</EventInstanceId>
<Mark>string</Mark>
</LessonMark>
<LessonMark>
<StudentId>int</StudentId>
<EventInstanceId>int</EventInstanceId>
<Mark>string</Mark>
</LessonMark>
</LessonMarks>
</LessonMarks>
</SetAttendanceMarks>
</soap12:Body>
</soap12:Envelope>
My code is as follows:
public boolean setAttendanceMarks(List<Mark> list) throws Exception
{
boolean result = false;
String methodName = "SetAttendanceMarks";
String soapAction = getHost() + "SetAttendanceMarks";
SoapObject lessMarksN = new SoapObject(getHost(), "LessonMarks");
for (Mark m : list)
{
PropertyInfo smProp =new PropertyInfo();
smProp.setName("LessonMark");
smProp.setValue(m);
smProp.setType(Mark.class);
lessMarksN.addProperty(smProp);
}
PropertyInfo cProp =new PropertyInfo();
cProp.setName("Count");
cProp.setValue(list.size());
cProp.setType(Integer.class);
SoapObject lessMarks = new SoapObject(getHost(), "LessonMarks");
lessMarks.addProperty(cProp);
lessMarks.addSoapObject(lessMarksN);
PropertyInfo sProp =new PropertyInfo();
sProp.setName("strSessionToken");
sProp.setValue(mSession);
sProp.setType(String.class);
SoapObject request = new SoapObject(getHost(), methodName);
request.addProperty(sProp);
request.addSoapObject(lessMarks);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(getURL());
androidHttpTransport.debug = true;
androidHttpTransport.call(soapAction, envelope);
String a = androidHttpTransport.requestDump;
String b = androidHttpTransport.responseDump;
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
SoapObject res = (SoapObject) resultsRequestSOAP.getProperty(0);
String resultStr = res.getPropertyAsString("Result");
if (resultStr.contentEquals("OK"))
{
result = true;
}
return result;
}
The error I get is as follows:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Server was unable to read request. ---> There is an error in XML document (1, 383). ---> The specified type was not recognized: name='LessonMarks', namespace='http://gsdregapp.net/', at <LessonMarks xmlns='http://gsdregapp.net/'>.</soap:Text>
</soap:Reason>
<soap:Detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
Can anybody tell me what I am doing wrong? I will be most grateful for any assistance!