我正在尝试使用KSOAP在Android上执行以下soap请求。它包含嵌套的soap对象列表。但是,当我收到错误时,我一定做错了。
我尝试生成的请求如下:
<?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>
我的代码如下:
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;
}
我得到的错误如下:
<?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>
有谁能告诉我我做错了什么?我将非常感谢任何帮助!
答案 0 :(得分:1)
您正在使用它的命名空间未被您的ws服务器识别。
SoapObject request = new SoapObject(getHost(), methodName);
看起来应该是这样的:
SoapObject request = new SoapObject("http://hostname.net/", methodName);
确保getHost()和getURL()正在检索相同的主机名,因为getURL()上的主机所期望的命名空间与getHost()发送的命名空间不同。
如果您不想使用wich命名空间,请使用SoapUI轻松读取wsdl并找到正确的命名空间