Beispiel #1
0
        internal IpcClientException(ExceptionFromXmlLight h, Exception inner) :
            base(h.Message, inner)
        {
            _h = h;

            Source = h.Source;
        }
Beispiel #2
0
        /// <summary>
        /// Sends a string to the server, gets the response string back.
        /// Works synchronously, so better call it from within a background
        /// thread to keep the UI responsive.
        /// </summary>
        public string Send(string request)
        {
            using (var wc = new MyWebClient())
            {
                wc.Encoding = Encoding.UTF8;
                try
                {
                    return(wc.UploadString(url, @"POST", request ?? string.Empty));
                }
                catch (WebException x)
                {
                    // Try to give user more details (which might have been
                    // marshalled from the server).

                    if (x.Status == WebExceptionStatus.ProtocolError)
                    {
                        var response = x.Response as HttpWebResponse;
                        if (response != null && response.StatusCode == HttpStatusCode.InternalServerError)
                        {
                            using (var stream = response.GetResponseStream())
                            {
                                if (stream != null)
                                {
                                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                                    {
                                        var resp = reader.ReadToEnd();
                                        if (ExceptionFromXmlLight.IsSerializedException(resp))
                                        {
                                            throw new IpcClientException(new ExceptionFromXmlLight(resp), x);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    throw;
                }
            }
        }