使用kso​​ap2将大小为5 mb的字节数组传递给Web服务时出现内存不足错误

时间:2013-02-13 07:52:51

标签: android ksoap2 android-ksoap2

我已将我的数据库文件转换为字节数组,并希望将其传递给我的Web服务以便保存在服务器上。我的数据库大小是5 MB,但是在添加soap_request时它会发出内存异常....我附加了我的代码,如下所示

File file = new File(filePath);
                int size = (int) file.length();
                byte[] bytes = new byte[size];

                Log.v(TAG, "File size in byte ==>"+size);
                try {
                    BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
                    buf.read(bytes, 0, bytes.length);
                    buf.close();
                    Log.v(TAG, "ByteArray = "+bytes.length);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                    SoapObject soap_request = new SoapObject(NAMESPACE, METHOD_NAME);
                    fileName = "TraceBaleAndroid_"+UserID+"_"+backupDateTime+".db";
                    Log.v(TAG, "FileName = "+fileName);
                    soap_request.addProperty("_FileName", fileName);

                    soap_request.addProperty("_ByteArray",bytes);
                    soap_request.addProperty("UserID", UserID);

                    Log.v(TAG, "soap_request _FileName= >>"+soap_request.getProperty(0));
                    //Log.v(TAG, "soap_request _ByteArray= >>"+soap_request.getProperty(1));
                    Log.v(TAG, "soap_request UserID= >>"+soap_request.getProperty(2));

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    new MarshalBase64().register(envelope);
                    envelope.setOutputSoapObject(soap_request);
                    envelope.dotNet = true;

                    Log.v(TAG,"Calling webservice....");
                    androidHttpTransportSE = new HttpTransportSE(URL);
                    androidHttpTransportSE.debug = true;
                    androidHttpTransportSE.call(SOAP_ACTION, envelope);

                    Log.v(TAG,"Getting result from webservice....");
                    SoapObject result = (SoapObject) envelope.bodyIn;
                    JSONObject response = new JSONObject(result.getProperty(0).toString());
                    Log.v(TAG, "Web Response...." + response.get(" Result "));

                    if (response.get(" Result ").equals("Uploading DataBase Backup To Server successfully"))
                    {
                        flag = true;
                        Log.v(TAG, "Database is uploaded .........");
                    }

            } catch (Exception e) {
                e.printStackTrace();
            }
            finally 
            {
                androidHttpTransportSE.reset();

            } 

1 个答案:

答案 0 :(得分:0)

带有5MB数据的SOAP请求对我来说真的很奇怪。但如果你确定需要这个,请检查这个问题的答案:How to increase heap size of an android application? 所有这些建议也适用于您的情况。