[mono-android] Monodroid : Intermittent failure in StreamReader.ReadLine() when reading json from web service

Glen Hassell mrhassell at gmail.com
Thu Nov 17 16:20:44 EST 2011


increase the maxArrayLength value because your byte[] array returned
exceeds the 16348 size. The max value you can set for maxArrayLength is
again the max Int32 number which is equal to 2147483647. Modify this
setting and your web service will be able to transfer large data between
your web service and the client application.

In *Web.config* , the web service reference bindings for clients are
generated.

"The maximum message size quota for incoming messages (65536) has been
exceeded. To increase the quota, use the MaxReceivedMessageSize property on
the appropriate binding element."

set it to the maximum of 2^31 - 1 or 2147483647 the biggest 32 bit number.

Pay attention on the transferMode, which by default is Buffered.

   - *Bufferred* means the request and response messages will be both
   buffered.

Other enumerations for transferMode:

   - *Streamed* which means both the request and response messages will be
   streamed, or
   - *StreamedRequest* where the request will be streamed while response
   message buffered, or
   - *StreamedResponse* where the request message will be buffered while
   response message streamed.

For those that don't know, Buffered means that the transfer will hold the
entire message in memory buffer all until the transfer is completed.
Streamed means that only the message headers will be buffered, while the
message body will be exposed as a stream.

Change to the maxReceivedMessageSize from 65536 to 2147483647 - if you
leave the transferMode="Buffered" we might get another error:

For TransferMode.Buffered, MaxReceivedMessageSize and MaxBufferSize must be
the same value. Parameter name: bindingElement

Both attributes require the same value, the MaxReceivedMessageSize is
larger than MaxBufferSize, if the whole message is buffered.

You have two options: a) Change the MaxBufferSize to size of 2147483647 b)
Make the transferMode to: Streamed, StreamedRequest or StreamedResponse.

"The decision to use either buffered or streamed transfers is a local
decision of the endpoint for HTTP transports. For HTTP transports, the
transfer mode does not propagate across a connection, or to proxy servers
or other intermediaries. Setting the transfer mode is not reflected in the
description of the service contract. After generating a proxy to a service,
you can (it is allowed but not required) edit the configuration file for
services intended to be used with streamed transfers to set the transfer
mode. For TCP and named pipe transports, the transfer mode is propagated as
a policy assertion."
http://msdn.microsoft.com/en-us/library/system.servicemodel.transfermode.aspx

On Fri, Nov 18, 2011 at 12:28 AM, kshitij limaye <klimaye at gmail.com> wrote:

> I posted this question on stackoverflow
>
>
> http://stackoverflow.com/questions/8167726/monodroid-intermittent-failure-when-reading-a-large-json-string-from-web-servi
>
> If this is the right forum to ask the question, I can give details here as
> well.
>
> I have had intermittent failures with StreamReader object's ReadLine and
> ReadToEnd methods.
>
> This essentially causes the app to freeze and get stuck.
>
> Why would StreamReader fail intermittently and how would one gracefully
> handle this without the app being stuck.
>
> Note : The exception by passes the try/catch block.
>
> Please advice.
>
> Thanks,
> Kshitij
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>


-- 
Glen Hassell
Inner Technique
http://innertech.com.au/
Office: 03 9687 0006
Mobile: +61 (0) 438 340 385
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monodroid/attachments/20111118/f0a24161/attachment-0001.html 


More information about the Monodroid mailing list