0

I am using ksoap2 to communicate to a .net webservice. However, when I submit a byte array from an image, I get an OutOfMemoryError.

I am using the following code:

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            new MarshalBase64().register(envelope); // serialization
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
            httpTransport.call(ADD_CLIENT_SOAP_ACTION, envelope);               
            Object response = null;
            response = envelope.getResponse();

StackTrace:

06-04 12:46:41.605: E/AndroidRuntime(9661): FATAL EXCEPTION: IntentService[SyncService]
06-04 12:46:41.605: E/AndroidRuntime(9661): java.lang.OutOfMemoryError
06-04 12:46:41.605: E/AndroidRuntime(9661):     at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:164)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at java.io.OutputStreamWriter.convert(OutputStreamWriter.java:236)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at java.io.OutputStreamWriter.write(OutputStreamWriter.java:225)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at java.io.BufferedWriter.write(BufferedWriter.java:249)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.kxml2.io.KXmlSerializer.writeEscaped(KXmlSerializer.java:137)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.kxml2.io.KXmlSerializer.text(KXmlSerializer.java:544)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.MarshalBase64.writeInstance(MarshalBase64.java:40)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:656)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:649)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:604)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:582)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:658)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:564)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:205)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.transport.Transport.createRequestData(Transport.java:111)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:120)
06-04 12:46:41.605: E/AndroidRuntime(9661):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
4

1 に答える 1

0

「大きな」画像とkSOAP2での最適化なしの組み合わせは、スマートフォンの限られたメモリには多分多すぎます。

kSOAP2は、送信するバイト配列のサイズの少なくとも5倍のメモリを一時的に使用すると推定します。これは、バイト配列自体に加えて、画像の他のコピーに加えて、保持する可能性があります。

したがって、それを機能させるには、メモリ消費を減らすことができるアプリ内の他の領域を見つける必要があります。または、完全なXMLメッセージとバイト配列のBase 64エンコード文字列をメモリに保持しないが、配列の小さなチャンクをエンコードしてそれらを直接送信するストリーミングアプローチを使用する別のSOAPライブラリを見つける必要があります。ネットワーク接続。

于 2012-06-04T12:51:32.153 に答える