Search code examples
androidandroid-ksoap2

Sending SOAP request with child elements in ksoap2


I am not even sure if that is what it is called what I want to do but I need to send something to the server that looks like this

<ECMMAID>int</ECMMAID>
  <appIncData>
    <int_inc_num>int</int_inc_num>
    <respTime>dateTime</respTime>
    <arriveTime>dateTime</arriveTime>
    <sceneControlledTime>dateTime</sceneControlledTime>
    <retStationTime>dateTime</retStationTime>
    <sceneClearedTime>dateTime</sceneClearedTime>
    <assist>boolean</assist>
    <unitNotes>string</unitNotes>
    <incidentPath>string</incidentPath>
    <totalCalculatedFromThePathMiles>double</totalCalculatedFromThePathMiles>
    <startOdmeterMilage>double</startOdmeterMilage>
    <endOdmeterMilage>double</endOdmeterMilage>
    <startEngineHours>double</startEngineHours>
    <startPumpHoursReading>double</startPumpHoursReading>
    <engineHours>double</engineHours>
    <currentPumpHoursReading>double</currentPumpHoursReading>
  </appIncData>

Now every other web service I have done with ksoap has always been just a bunch of properties with values but nothing where you have a property children under the tag

basically just like this

request.addProperty("ECMMAID","");
request.addProperty("Name",);
request.addProperty("Content",);
request.addProperty("STID",);
request.addProperty("IncNum",);
request.addProperty("Notes","");
request.addProperty("uploader",);

How do I send something like I need to in ksoap or should I just use HttpPost?


Solution

  • Try something similar to the code below. I used a similar code in my app to send xml format data to server.

     PropertyInfo req = new PropertyInfo();
            req.name="appIncData";// may be different in your case  
            req.type=String.class;
            req.setValue("<ECMMAID>"+int+"</ECMMAID>"+
                         "<appIncData>"+
                        "<int_inc_num>"+int+"</int_inc_num>"+
                        " <respTime>"+dateTime+"</respTime>"+
            "</appIncData>");
    
            request.addProperty(req);