Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

HTTPClient Issue with System.ObjectDisposedException: Cannot access a disposed object.

$
0
0

I am using HTTPClient to post some data to a web service. It works fine until, I suspect that the payload is too large and I start getting this unhandled exception. Even so,it is only around 5mb or so. I can't get any more exception details as the exception handler doesn't catch it and the app crashes. I have only tried it on IOS so far.

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.

I have tried manually submitting the payload using soap tools and its fine, so I know its not a server issue.

                    string result = null;
                    using (var client = new HttpClient())
                    {                                               

                        HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://www.abc.com/DataTables.asmx");

                        message.Headers.Add("SOAPAction", "https://www.abc.com/ws/wsDataAPI/setImport");


                        message.Content = new StringContent(soapXML, Encoding.UTF8, "text/xml");

                        try
                        {
                //Its crashing here
                            using (var response = await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead))
                            {
                                if (response.IsSuccessStatusCode)
                                {
                                    /
                                    result = await response.Content.ReadAsStringAsync();

                                }
                            }
                        }
                        catch (Exception ex)
                        {
                //The exception should get caught here but does not
                            return new ExceptionWrapper(ex);      
                        }
                  }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>