private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            TransportExchange exchange = (TransportExchange)asynchronousResult.AsyncState;

            try
            {
                // End the operation
                string responseString;

                using (HttpWebResponse response = (HttpWebResponse)exchange.request.EndGetResponse(asynchronousResult))
                {
                    using (Stream streamResponse = response.GetResponseStream())
                    {
                        using (StreamReader streamRead = new StreamReader(streamResponse))
                            responseString = streamRead.ReadToEnd();
                    }

                    if (response.Cookies != null)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            exchange.AddCookie(cookie);
                        }
                    }

                    response.Close();
                }
                exchange.messages = DictionaryMessage.parseMessages(responseString);

                exchange.listener.onMessages(exchange.messages);
                exchange.Dispose();
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("operation has timed out")) // Supress timeout messages due to inactivity
                {
                    exchange.listener.onException(e, ObjectConverter.ToListOfIMessage(exchange.messages));
                }
                exchange.Dispose();
            }
        }
Exemplo n.º 2
0
        private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            TransportExchange exchange = (TransportExchange)asynchronousResult.AsyncState;

            try
            {
                // End the operation
                string responseString;
                using (HttpWebResponse response = (HttpWebResponse)exchange.request.EndGetResponse(asynchronousResult))
                {
                    using (Stream streamResponse = response.GetResponseStream())
                    {
                        using (StreamReader streamRead = new StreamReader(streamResponse))
                            responseString = streamRead.ReadToEnd();
                    }
                    //Console.WriteLine("Received message(s): {0}", responseString);

#if !SILVERLIGHT
                    if (response.Cookies != null)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            exchange.AddCookie(cookie);
                        }
                    }
#endif
                    response.Close();
                }
                exchange.messages = DictionaryMessage.parseMessages(responseString);

                exchange.listener.onMessages(exchange.messages);
                exchange.Dispose();
            }
            catch (Exception e)
            {
                exchange.listener.onException(e, ObjectConverter.ToListOfIMessage(exchange.messages));
                exchange.Dispose();
            }
        }