0

I am working with SOAP Parsing in android. In my application there is one point where I have to download large amount of data where byte array type of data are also there.

For the solution I have referred the link Very large SOAP response - Android- out of memory error but not able to get how can it works with my soap object.

The method which I am using to get the soap response is as follows:

public SoapObject taskDetail() {

    SoapObject result = null;

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("ID", "4");
    request.addProperty("fromDate", "02/06/2013");       
        request.addProperty("toDate", "02/06/2013");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);

    AndroidHttpTransport transport = new AndroidHttpTransport(URL);

    transport.debug = true;

    try {
        transport.call(SOAP_ACTION, envelope);

        result = (SoapObject)envelope.getResponse();

        for(int i=0; i<result.getPropertyCount(); i++) {
                SoapObject view_task_master = (SoapObject) result.getProperty(i);

        screen = view_task_master.getProperty("Screen").toString();
        Log.i("screen",screen);

        date = view_task_master.getProperty("Createddate").toString();
        Log.i("date",date);

    }




        } 
        catch (IOException e) {
            Log.i("IOException",e.getMessage());
        } 
        catch (XmlPullParserException e) {
            Log.i("XMLPullParserException",e.getMessage());
        }
            return result;
    }

I know the main problem is that because of the large data the result object can't handle it.
Please help...Thanks in advance...!!

Community
  • 1
  • 1
Manali Sheth
  • 379
  • 2
  • 5
  • 17

2 Answers2

2
  • Try to use AynckTask for soap request -because It doesn't take much heap memory

Two strategies to help you solve this problem:

Save your SOAP XML stream directly to disk as you download it. Don't store it in memory. Parse it using a SAX-style parser, where you don't load the whole DOM in memory, but rather parse it in chunks. Depending on the kind of XML you are handling, using SAX parsers is usually harder in code; you will have to keep track of many things yourself, and you won't be able to "jump" from section to section of your DOM tree. But the memory consumption will be way lower.

Take note, however, that many "high-level" network communication libraries usually load the whole XML DOM in memory, which might be the case here. You will probably have to create and manage the HTTP connection yourself, and then manually parse the result.

Prabu
  • 1,441
  • 15
  • 20
  • @Prabu...Thanks for the answer...In my application, I have to do SOAP request so many times and every time I am working with Asynctask task and its working fine. But at this time my xml response is too large, that's why out of memory problem is occured. – Manali Sheth Apr 13 '13 at 06:13
0

Use ContentHandler. When it finds tag which contains data, use characters() method to get characters array from the input stream and write it to the file or DB. This way you do not need to keep all data in ram. (this is a solution for the case when your soap object contains BLOB)

Also keep in mind that AsyncTask is not the best way to perform long-running network requests(only one AsyncTask can run at the moment on 3.0+ if you start it with execute())

Johnny Doe
  • 3,280
  • 4
  • 29
  • 45