来自服务器阵列的Android KSoap2响应为空

时间:2012-04-03 15:38:55

标签: android arrays post response ksoap2

我搜索了很多,但没有找到任何帮助,所以我希望有人可以解释一下这个问题。

我想使用KSoap发送一个数组,我按如下方式执行:

首先,我构建这样的soap对象:

SoapObject request = new SoapObject(GENERICNAMESPACE, SOAP_METHOD_NAME);

PropertyInfo attr = new PropertyInfo();
        attr.name = "patientLogin";
        attr.type = PropertyInfo.STRING_CLASS;
        attr.namespace = GENERICNAMESPACE;
        attr.setValue(patientId);
        request.addProperty(attr);

        //could be patientPassword
        attr = new PropertyInfo();
        attr.name = "passwd";
        attr.type = PropertyInfo.STRING_CLASS;
        attr.namespace = GENERICNAMESPACE;
        attr.setValue(patientPassword);
        request.addProperty(attr);

        Vector vectorOfIDsRead = new Vector();
        vectorOfIDsRead.addElement(idsRead);

        attr = new PropertyInfo();
        attr.name = "IDsRead";
        attr.type = PropertyInfo.STRING_CLASS;
        attr.namespace = GENERICNAMESPACE;
        attr.setValue(vectorOfIDsRead);
        request.addProperty(attr);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER10);
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(GENERICURL);
        androidHttpTransport.debug = true;
        try {
            androidHttpTransport.call(GENERICSOAP_ACTION_URL+"feedbackRead", envelope);

            SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope
                    .getResponse();

            //log request
            Log.e("SendFeedbackRead", "/////////////////////RequestDump////////////////////");
            Log.e("SendFeedbackRead", androidHttpTransport.requestDump.toString());     
            Log.e("SendFeedbackRead", "/////////////////////////////////////////");

            //log request
            Log.e("SendFeedbackRead", "///////////////////ResponseDump/////////////////");
            Log.e("SendFeedbackRead", androidHttpTransport.responseDump.toString());        
            Log.e("SendFeedbackRead", "/////////////////////////////////////////");

            Log.e("FeedbackRead",
                    "FeedbackRead : " + resultsRequestSOAP.toString());

            return resultsRequestSOAP.toString();
        } catch (Exception e) {
            Log.e("FeedbackRead", "SENDFEEDBACKREAD : " + e);
            return e.getMessage();
        }

请求转储显示我正在发送:

<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header />
<v:Body>
<n0:feedbackRead id="o0" c:root="1" xmlns:n0="http://testing.starburst.com/GenericWS">
<n0:patientLogin i:type="d:string">patient1</n0:patientLogin>
<n0:passwd i:type="d:string">pat1</n0:passwd>
<n0:IDsRead i:type="c:Array" c:arrayType="d:anyType[1]"><item i:type="d:string">1234test</item></n0:IDsRead></n0:feedbackRead>
</v:Body>
</v:Envelope>

但是我得到的回应表明列表是空的。

feedbackRead,空提交的ID列表!

它没有一个值。

有人能指出我正确的方向吗?

感谢。

1 个答案:

答案 0 :(得分:0)

我认为你的错误就在这里:

Vector vectorOfIDsRead = new Vector();
vectorOfIDsRead.addElement(idsRead);
attr = new PropertyInfo();
attr.name = "IDsRead";
attr.type = PropertyInfo.STRING_CLASS;
attr.namespace = GENERICNAMESPACE;
attr.setValue(vectorOfIDsRead);
request.addProperty(attr);

您将vectorOfIDsRead声明为Vector,但您将该类型设为STRING_CLASS。 它将是:

attr.setType(vectorOfIDsRead.getClass());

然后:

... create the envelope ...
envelope.addMapping(NAMESPACE, "IDsRead", new Vector().getClass());

希望它有所帮助。另请看一下:http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives

编辑:无论如何,您可以放置​​SOAP_METHOD_NAME的方法签名吗?