コード例 #1
0
 private void populateFromMWSException(MwsException e)
 {
     if (e.StatusCode != null)
     {
         this.statusCode = (int)e.StatusCode;
     }
     if (e.Message != null)
     {
         this.message = e.Message;
     }
     if (e.errorCode != null)
     {
         this.errorCode = e.ErrorCode;
     }
     if (e.errorType != null)
     {
         this.errorType = e.ErrorType;
     }
     if (e.detail != null)
     {
         this.detail = e.Detail;
     }
     if (e.xml != null)
     {
         this.xml = e.XML;
     }
     if (e.ResponseHeaderMetadata != null)
     {
         this.rhmd = e.ResponseHeaderMetadata;
     }
 }
コード例 #2
0
ファイル: MwsAQCall.cs プロジェクト: ACGDev/ACGConsole
        /// <summary>
        /// Creates a request and invokes it
        /// </summary>
        /// <returns></returns>
        /// <exception cref="MwsException">Exceptions from invoking the request</exception>
        public IMwsReader invoke()
        {
            string         responseBody;
            string         message;
            HttpStatusCode statusCode = default(HttpStatusCode);

            /* Add required request parameters */
            AddRequiredParameters();
            string queryString = GetParametersAsString(parameters);
            int    retries     = 0;

            do
            {
                /* Submit the request and read response body */
                try
                {
                    request = connection.GetHttpClient(serviceEndPoint.URI);
                    byte[] requestData = new UTF8Encoding().GetBytes(queryString);
                    request.ContentLength = requestData.Length;
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(requestData, 0, requestData.Length);
                    }
                    using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
                    {
                        statusCode             = httpResponse.StatusCode;
                        message                = httpResponse.StatusDescription;
                        ResponseHeaderMetadata = GetResponseHeaderMetadata(httpResponse);
                        StreamReader reader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8);
                        responseBody = reader.ReadToEnd();
                    }
                    if (statusCode == HttpStatusCode.OK)
                    {
                        return(new MwsXmlReader(responseBody));
                    }
                    MwsException e = new MwsException((int)statusCode, message, null, null, responseBody, ResponseHeaderMetadata);

                    if (statusCode == HttpStatusCode.InternalServerError)
                    {
                        if (PauseIfRetryNeeded(retries++))
                        {
                            continue;
                        }
                    }
                    throw e;
                }
                /* Web exception is thrown on unsuccessful responses */
                catch (WebException we)
                {
                    using (HttpWebResponse httpErrorResponse = (HttpWebResponse)we.Response as HttpWebResponse)
                    {
                        if (httpErrorResponse == null)
                        {
                            throw new MwsException(we);
                        }
                        statusCode = httpErrorResponse.StatusCode;
                        using (StreamReader reader = new StreamReader(httpErrorResponse.GetResponseStream(), Encoding.UTF8))
                        {
                            responseBody = reader.ReadToEnd();
                        }
                    }
                    //retry logic
                    if (PauseIfRetryNeeded(retries++))
                    {
                        continue;
                    }
                    throw new MwsException((int)statusCode, null, null, null, responseBody, null);
                }

                /* Catch other exceptions, attempt to convert to formatted exception,
                 * else rethrow wrapped exception */
                catch (Exception e)
                {
                    throw new MwsException(e);
                }
            } while (true);
        }