Android KSoap2 Ответ от серверного массива пуст - PullRequest
0 голосов
/ 03 апреля 2012

Я много искал, но не нашел никакой помощи, поэтому надеюсь, что кто-нибудь сможет пролить свет на этот вопрос.

Я хочу отправить массив с помощью KSoap, и я делаю это следующим образом:

Сначала я создаю объект мыла следующим образом:

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 голосов
/ 03 апреля 2012

Я думаю, что ваша ошибка здесь:

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?

...