コード例 #1
0
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails)
        {
            HttpStatusCode httpStatusCode;
            string         operationId;

            return(TryGetExceptionDetails(exception, out errorDetails, out httpStatusCode, out operationId));
        }
コード例 #2
0
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
        {
            errorDetails = null;
            httpStatusCode = 0;
            operationId = null;

            if (exception == null)
            {
                return false;
            }

            if (exception.Message == "Internal Server Error")
            {
                httpStatusCode = HttpStatusCode.InternalServerError;
                return true;
            }

            WebException wex = exception.InnerException as WebException;

            if (wex == null)
            {
                return false;
            }

            HttpWebResponse response = wex.Response as HttpWebResponse;
            if (response == null)
            {
                return false;
            }

            //httpStatusCode = response.StatusCode;
            //if (httpStatusCode == HttpStatusCode.Forbidden)
            //{
            //    return true;
            //}

            if (response.Headers != null)
            {
                operationId = response.Headers[Constants.OperationTrackingIdHeader];
            }

            // Don't wrap responseStream in a using statement to prevent it
            // from being disposed twice (as it's disposed by reader if it is
            // successfully disposed).
            Stream responseStream = null;
            try
            {
                responseStream = response.GetResponseStream();
                if (responseStream.Length == 0)
                {
                    return false;
                }

                try
                {
                    using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(responseStream, new XmlDictionaryReaderQuotas()))
                    {
                        // Release the reference to responseStream since it
                        // will be closed when the reader is diposed
                        responseStream = null;

                        DataContractSerializer ser = new DataContractSerializer(typeof(ServiceManagementError));
                        errorDetails = (ServiceManagementError)ser.ReadObject(reader, true);
                    }
                }
                catch (SerializationException)
                {
                    return false;
                }
            }
            finally
            {
                if (responseStream != null)
                {
                    responseStream.Dispose();
                }
            }
            
            return true;
        }
コード例 #3
0
 public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails)
 {
     HttpStatusCode httpStatusCode;
     string operationId;
     return TryGetExceptionDetails(exception, out errorDetails, out httpStatusCode, out operationId);
 }
コード例 #4
0
        public static bool TryGetExceptionDetails(CommunicationException exception, out ServiceManagementError errorDetails, out HttpStatusCode httpStatusCode, out string operationId)
        {
            errorDetails   = null;
            httpStatusCode = 0;
            operationId    = null;

            if (exception == null)
            {
                return(false);
            }

            if (exception.Message == "Internal Server Error")
            {
                httpStatusCode = HttpStatusCode.InternalServerError;
                return(true);
            }

            WebException wex = exception.InnerException as WebException;

            if (wex == null)
            {
                return(false);
            }

            HttpWebResponse response = wex.Response as HttpWebResponse;

            if (response == null)
            {
                return(false);
            }

            //httpStatusCode = response.StatusCode;
            //if (httpStatusCode == HttpStatusCode.Forbidden)
            //{
            //    return true;
            //}

            if (response.Headers != null)
            {
                operationId = response.Headers[Constants.OperationTrackingIdHeader];
            }

            // Don't wrap responseStream in a using statement to prevent it
            // from being disposed twice (as it's disposed by reader if it is
            // successfully disposed).
            Stream responseStream = null;

            try
            {
                responseStream = response.GetResponseStream();
                if (responseStream.Length == 0)
                {
                    return(false);
                }

                try
                {
                    using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(responseStream, new XmlDictionaryReaderQuotas()))
                    {
                        // Release the reference to responseStream since it
                        // will be closed when the reader is diposed
                        responseStream = null;

                        DataContractSerializer ser = new DataContractSerializer(typeof(ServiceManagementError));
                        errorDetails = (ServiceManagementError)ser.ReadObject(reader, true);
                    }
                }
                catch (SerializationException)
                {
                    return(false);
                }
            }
            finally
            {
                if (responseStream != null)
                {
                    responseStream.Dispose();
                }
            }

            return(true);
        }