1

I'm trying to send an array/ list of Complex objects using ksoap from android to vb.net webservice. I can send complex object but the list is giving me trouble.

This is the android code

private class SampleTask extends AsyncTask<String, Void, String> {

        @Override
        protected void onPreExecute() {
            // if you want, start progress dialog here
        }

        @Override
        protected String doInBackground(String... urls) {
            String webResponse = "";
            try {
                final String NAMESPACE = "http://sample.org/";
                final String URL = "http://192.168.1.103:8081/MySampleService.asmx";
                final String SOAP_ACTION = "http://sample.org/SampleWS";
                final String METHOD_NAME = "SampleWS";

                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                 List<MediSenseLog> logs =  new ArrayList<MediSenseLog>();

                 MediSenseLog log1 = new MediSenseLog();
                    log1.setID(Integer.parseInt("1"));
                    log1.setLogDate("2014-05-13");

                     MediSenseLog log2 = new MediSenseLog();
                        log1.setID(Integer.parseInt("2"));
                        log1.setLogDate("2014-05-14");

                    logs.add(log1);
                    logs.add(log2);

                    SoapObject soapLogs = new SoapObject(NAMESPACE, "logs");

                    for (MediSenseLog i : logs){
                        soapLogs.addProperty("MediSenseLog", i);
                    }
                    request.addSoapObject(soapLogs);


                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(request);
                envelope.addMapping(NAMESPACE, "MediSenseLog",new MediSenseLog().getClass());

                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.debug = true;
                androidHttpTransport.call(SOAP_ACTION, envelope);
                Log.d("HTTP REQUEST ",androidHttpTransport.requestDump);
                Log.d("HTTP RESPONSE", androidHttpTransport.responseDump);
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                Log.d("ComplexWS", response.toString());
                webResponse = response.toString();

            } catch (Exception e) {
            }

            return webResponse;
        }

        @Override
        protected void onPostExecute(String result) {

            Toast.makeText(getApplicationContext(), "Synchonization Completed...",Toast.LENGTH_LONG).show();
            Log.d("ComplexWS","return val is "+result);

        }
    }

This is the .net code

 Public Class MediSenseLog
    Public ID As Integer
    Public LogDate As String

End Class

<WebMethod()> _
Public Function SampleWS(ByVal logs As MediSenseLog()) As String
    Return logs(1).LogDate.ToString()
End Function

This is the request using requestdump

 <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>
        <Sample xmlns="http://sample.org/" id="o0" c:root="1">
            <n0:logs i:type="n0:logs" xmlns:n0="http://sample.org/">
                <MediSenseLog i:type="n0:MediSenseLog">
                    <ID i:type="d:int">2</ID>
                    <LogDate i:type="d:string">2014-05-14</LogDate>
                </MediSenseLog>
                <MediSenseLog i:type="n0:MediSenseLog">
                    <ID i:type="d:int">0</ID>
                    <LogDate i:null="true" />
                </MediSenseLog>
            </n0:logs>
        </Sample>
    </v:Body>
</v:Envelope>

This is the response using response dump

 <?xml version="1.0" encoding="utf-8"?><soap:Envelope        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <SampleResponse xmlns="http://sample.org/">
        <SampleResult />
    </SampleResponse>
</soap:Body>
</soap:Envelope>

The return Value is blank.

Can anyone assist?

1
  • Please send me your code Commented Jan 13, 2016 at 10:32

1 Answer 1

1

Found the error

just change this

 log1.setID(Integer.parseInt("2"));
log1.setLogDate("2014-05-14");

to

log2.setID(Integer.parseInt("2"));
log2.setLogDate("2014-05-14");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.