Sto provando a caricare un oggetto complesso su un webservice WCF utilizzando KSoap2 Android e ho qualche difficoltà a farlo. Ho raggiunto con successo chiamate al webservice quando uso SoapUI e compilo i dati a mano. Il successo di richiesta SoapUI generati è la seguente:Ksoap2 Android: come specificare uno spazio dei nomi per le proprietà figlio di un oggetto complesso?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:fpm="http://schemas.datacontract.org/2004/07/FPMobileServices">
<soapenv:Header/>
<soapenv:Body>
<tem:CommitOne>
<tem:qr>
<fpm:ClientID>8aa2f6a4-4d15-4b4c-9cac-fb2478d0d27a</fpm:ClientID>
<fpm:CreatedBy>admin</fpm:CreatedBy>
<fpm:CreatedDate>2012-03-01T19:50:37</fpm:CreatedDate>
<fpm:DimensionID>8a02a339-b5a7-4c76-b95f-5891ef57736d</fpm:DimensionID>
<fpm:ImageID>b76c7bcc-a8f8-49ff-94c6-08cd2e05b1a8</fpm:ImageID>
<fpm:IndicatorID>4637b333-701d-4d03-a708-4de48569be84</fpm:IndicatorID>
<fpm:LoanOperationNumber>6-2011-72978</fpm:LoanOperationNumber>
<fpm:ModifiedBy>admin</fpm:ModifiedBy>
<fpm:ModifiedDate>2012-03-01T19:50:37</fpm:ModifiedDate>
<fpm:QuestionaireCompletedDate>2012-03-01T19:50:54</fpm:QuestionaireCompletedDate>
<fpm:QuestionnaireID>99967f70-8161-4922-929f-03136a389ba6</fpm:QuestionnaireID>
<fpm:ResultID>95fa03b5-80af-479d-9dec-f2bf94baf3cd</fpm:ResultID>
<fpm:ResultWeighting>0</fpm:ResultWeighting>
<fpm:StatusLevelID>03a91cd6-93cd-4503-a676-efa2967e82a7</fpm:StatusLevelID>
<fpm:UploadID>141D6A1F-8FFD-4CA4-8073-009338F22B13</fpm:UploadID>
</tem:qr>
</tem:CommitOne>
</soapenv:Body>
</soapenv:Envelope>
La richiesta generata dal mio codice Java è:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<CommitOne xmlns="http://tempuri.org/" id="o0" c:root="1">
<qr>
<ClientID>8aa2f6a4-4d15-4b4c-9cac-fb2478d0d27a</ClientID>
<LoanOperationNumber>6-2011-72978</LoanOperationNumber>
<CreatedBy i:null="true" />
<CreatedDate>2012-03-01T19:50:37</CreatedDate>
<DimensionID>8a02a339-b5a7-4c76-b95f-5891ef57736d</DimensionID>
<ImageID>b76c7bcc-a8f8-49ff-94c6-08cd2e05b1a8</ImageID>
<IndicatorID>4637b333-701d-4d03-a708-4de48569be84</IndicatorID>
<ModifiedBy i:null="true" />
<ModifiedDate i:null="true" />
<QuestionnaireCompletedDate>2012-03-01T19:50:54</QuestionnaireCompletedDate>
<QuestionnaireID>99967f70-8161-4922-929f-03136a389ba6</QuestionnaireID>
<ResultID i:type="d:string">95fa03b5-80af-479d-9dec-f2bf94baf3cc</ResultID>
<ResultWeighting>0</ResultWeighting>
<StatusLevelID>03a91cd6-93cd-4503-a676-efa2967e82a7</StatusLevelID>
<UploadID i:type="d:string">8ffa3665-b691-486f-91a0-ebbe8575896c</UploadID>
</qr>
</CommitOne>
</v:Body>
La differenza principale tra i due sembra essere il prefissi/spazi dei nomi . Per qualche motivo quando l'oggetto "qr" arriva nel mio codice .NET, tutte le sue proprietà sono null/zero.
Ho provato 2 diversi approcci nel mio codice Java, cercando di impostare il mio oggetto "qr" come PropertyInfo:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// build request object
PropertyInfo qrPi = new PropertyInfo();
qrPi.setName("qr");
qrPi.setType(qr.getClass());
qrPi.setValue(qr);
request.addProperty(qrPi);
E anche impostando i miei "qr" come SoapObject e quindi utilizzando .addProperty:
SoapObject result = new SoapObject(NAMESPACE, "qr");
result.addProperty("ClientID", (String) qr.getClientID());
result.addProperty("CreatedBy", (String) qr.getCreatedBy());
result.addProperty("CreatedDate", (String) qr.getCreatedDate());
result.addProperty("DimensionID", (String) qr.getDimensionID());
result.addProperty("ImageID", (String) qr.getImageID());
result.addProperty("IndicatorID", (String) qr.getIndicatorID());
result.addProperty("LoanOperationNumber", (String) qr.getLoanOperationNumber());
result.addProperty("ModifiedBy", (String) qr.getModifiedBy());
result.addProperty("ModifiedDate", (String) qr.getModifiedDate());
result.addProperty("QuestionnaireCompletedDate", (String) qr.getQuestionnaireCompletedDate());
result.addProperty("QuestionnaireID", (String) qr.getQuestionnaireID());
result.addProperty("ResultID", (String) qr.getResultID());
result.addProperty("ResultWeighting", qr.getResultWeighting());
result.addProperty("StatusLevelID", (String) qr.getStatusLevelID());
result.addProperty("UploadID", (String) qr.getUploadID());
request.addSoapObject(result);
Ma entrambi questi approcci ottenere lo stesso risultato - tutti i campi mia dell'oggetto "qr" sono nulli quando si arriva nel mio webservice. Ho cercato domande simili su StackOverflow e trovato this ma non riesco a capire come applicarlo al mio caso.
Qualcuno può aiutare a chiarire la situazione?
Hi breadbin, nel tuo spazio dei nomi di esempio ha il prefisso "tem" e "fpm". Come possiamo aggiungere questi prefissi nel nostro PropertyInfo? o sarà curato dalla biblioteca stessa? – silwar
@silwar, vedere la riga "pi.setNameSpace (QR_NAMESPACE)" nel codice sopra: si tratta di impostare una stringa come spazio dei nomi per l'oggetto PropertyInfo. – breadbin