コード例 #1
0
        public static void Main(string[] args)
        {
            // TODO: Set the below configuration variables before attempting to run

            // Developer AWS access key
            string accessKey = "replaceWithAccessKey";

            // Developer AWS secret key
            string secretKey = "replaceWithSecretKey";

            // The client application name
            string appName = "CSharpSampleCode";

            // The client application version
            string appVersion = "1.0";

            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            string serviceURL = "replaceWithServiceURL";

            // Create a configuration object
            FBAInventoryServiceMWSConfig config = new FBAInventoryServiceMWSConfig();

            config.ServiceURL = serviceURL;
            // Set other client connection configurations here if needed
            // Create the client itself
            FBAInventoryServiceMWS client = new FBAInventoryServiceMWSClient(accessKey, secretKey, appName, appVersion, config);

            FBAInventoryServiceMWSSample sample = new FBAInventoryServiceMWSSample(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;
                // response = sample.InvokeGetServiceStatus();
                // response = sample.InvokeListInventorySupply();
                // response = sample.InvokeListInventorySupplyByNextToken();
                Console.WriteLine("Response:");
                ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata;
                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                string responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (FBAInventoryServiceMWSException ex)
            {
                // Exception properties are important for diagnostics.
                ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata;
                Console.WriteLine("Service Exception:");
                if (rhmd != null)
                {
                    Console.WriteLine("RequestId: " + rhmd.RequestId);
                    Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                }
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("StatusCode: " + ex.StatusCode);
                Console.WriteLine("ErrorCode: " + ex.ErrorCode);
                Console.WriteLine("ErrorType: " + ex.ErrorType);
                throw ex;
            }
        }
コード例 #2
0
        /**
         * Invoke request and return response
         */
        private T Invoke <T>(IDictionary <String, String> parameters)
        {
            String                 actionName   = parameters["Action"];
            T                      response     = default(T);
            String                 responseBody = null;
            HttpStatusCode         statusCode   = default(HttpStatusCode);
            ResponseHeaderMetadata rhm          = null;

            if (String.IsNullOrEmpty(config.ServiceURL))
            {
                throw new MarketplaceWebServiceOrdersException(
                          new ArgumentException(
                              "Missing serviceURL configuration value. You may obtain a list of valid MWS URLs by consulting the MWS Developer's Guide, or reviewing the sample code published along side this library."));
            }

            /* Add required request parameters */
            AddRequiredParameters(parameters);

            String queryString = GetParametersAsString(parameters);

            byte[] requestData = new UTF8Encoding().GetBytes(queryString);
            bool   shouldRetry = true;
            int    retries     = 0;

            do
            {
                HttpWebRequest request = ConfigureWebRequest(requestData.Length);
                /* Submit the request and read response body */
                try
                {
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(requestData, 0, requestData.Length);
                    }
                    using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
                    {
                        statusCode = httpResponse.StatusCode;


                        rhm = new ResponseHeaderMetadata(
                            httpResponse.GetResponseHeader("x-mws-request-id"),
                            httpResponse.GetResponseHeader("x-mws-response-context"),
                            httpResponse.GetResponseHeader("x-mws-timestamp"));

                        StreamReader reader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8);
                        responseBody = reader.ReadToEnd();
                    }
                    /* Attempt to deserialize response into <Action> Response type */
                    XmlSerializer serializer = new XmlSerializer(typeof(T));
                    using (StringReader responseReader = new StringReader(responseBody))
                    {
                        response = (T)serializer.Deserialize(responseReader);

                        PropertyInfo pi = typeof(T).GetProperty("ResponseHeaderMetadata");
                        pi.SetValue(response, rhm, null);
                    }
                    shouldRetry = false;
                }
                /* Web exception is thrown on unsucessful responses */
                catch (WebException we)
                {
                    shouldRetry = false;
                    using (HttpWebResponse httpErrorResponse = (HttpWebResponse)we.Response as HttpWebResponse)
                    {
                        if (httpErrorResponse == null)
                        {
                            throw new MarketplaceWebServiceOrdersException(we);
                        }
                        statusCode = httpErrorResponse.StatusCode;
                        using (StreamReader reader = new StreamReader(httpErrorResponse.GetResponseStream(), Encoding.UTF8))
                        {
                            responseBody = reader.ReadToEnd();
                        }
                    }

                    /* Attempt to deserialize response into ErrorResponse type */
                    using (StringReader responseReader = new StringReader(responseBody))
                    {
                        try
                        {
                            XmlSerializer serializer    = new XmlSerializer(typeof(ErrorResponse));
                            ErrorResponse errorResponse = (ErrorResponse)serializer.Deserialize(responseReader);
                            Error         error         = errorResponse.Error[0];

                            bool retriableError =
                                (statusCode == HttpStatusCode.InternalServerError ||
                                 statusCode == HttpStatusCode.ServiceUnavailable);

                            retriableError = retriableError && !(REQUEST_THROTTLED_ERROR_CODE.Equals(error.Code));
                            if (retriableError && retries < config.MaxErrorRetry)
                            {
                                shouldRetry = true;
                                PauseOnRetry(++retries, statusCode, rhm);
                                continue;
                            }
                            else
                            {
                                shouldRetry = false;
                            }

                            /* Throw formatted exception with information available from the error response */
                            throw new MarketplaceWebServiceOrdersException(
                                      error.Message,
                                      statusCode,
                                      error.Code,
                                      error.Type,
                                      errorResponse.RequestId,
                                      errorResponse.ToXML(),
                                      rhm);
                        }
                        catch (MarketplaceWebServiceOrdersException mwsErr)
                        {
                            throw mwsErr;
                        }
                        catch (Exception e)
                        {
                            throw ReportAnyErrors(responseBody, statusCode, rhm, e);
                        }
                    }
                }

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

            return(response);
        }
コード例 #3
0
        /**
         * Look for additional error strings in the response and return formatted exception
         */
        private MarketplaceWebServiceOrdersException ReportAnyErrors(String responseBody, HttpStatusCode status, ResponseHeaderMetadata rhm, Exception e)
        {
            MarketplaceWebServiceOrdersException ex = null;

            if (responseBody != null && responseBody.StartsWith("<"))
            {
                Match errorMatcherOne = Regex.Match(responseBody, "<RequestId>(.*)</RequestId>.*<Error>" +
                                                    "<Code>(.*)</Code><Message>(.*)</Message></Error>.*(<Error>)?", RegexOptions.Multiline);
                Match errorMatcherTwo = Regex.Match(responseBody, "<Error><Code>(.*)</Code><Message>(.*)" +
                                                    "</Message></Error>.*(<Error>)?.*<RequestID>(.*)</RequestID>", RegexOptions.Multiline);

                if (errorMatcherOne.Success)
                {
                    String requestId = errorMatcherOne.Groups[1].Value;
                    String code      = errorMatcherOne.Groups[2].Value;
                    String message   = errorMatcherOne.Groups[3].Value;

                    ex = new MarketplaceWebServiceOrdersException(message, status, code, "Unknown", requestId, responseBody, rhm);
                }
                else if (errorMatcherTwo.Success)
                {
                    String code      = errorMatcherTwo.Groups[1].Value;
                    String message   = errorMatcherTwo.Groups[2].Value;
                    String requestId = errorMatcherTwo.Groups[4].Value;

                    ex = new MarketplaceWebServiceOrdersException(message, status, code, "Unknown", requestId, responseBody, rhm);
                }
                else
                {
                    ex = new MarketplaceWebServiceOrdersException("Internal Error", status, rhm);
                }
            }
            else
            {
                ex = new MarketplaceWebServiceOrdersException("Internal Error", status, rhm);
            }
            return(ex);
        }
コード例 #4
0
 public MarketplaceWebServiceProductsException(string message, HttpStatusCode statusCode, ResponseHeaderMetadata rhmd)
     : base((int)statusCode, message, null, null, null, rhmd)
 {
 }
コード例 #5
0
 public MarketplaceWebServiceProductsException(string message, HttpStatusCode statusCode, string errorCode,
                                               string errorType, string requestId, string xml, ResponseHeaderMetadata rhmd)
     : base((int)statusCode, message, errorCode, errorType, xml, rhmd)
 {
 }
 public MWSMerchantFulfillmentServiceException(string message, HttpStatusCode statusCode, string errorCode,
                                               string errorType, string requestId, string xml, ResponseHeaderMetadata rhmd)
     : base((int)statusCode, message, errorCode, errorType, xml, rhmd)
 {
 }
        public static void Main(string[] args)
        {
            // TODO: Set the below configuration variables before attempting to run

            // Developer AWS access key
            string accessKey = "";

            // Developer AWS secret key
            string secretKey = "";

            // The client application name
            string appName = "CSharpSampleCode";

            // The client application version
            string appVersion = "1.0";

            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            string serviceURL = "https://mws.amazonservices.com";

            // Create a configuration object
            MarketplaceWebServiceProductsConfig config = new MarketplaceWebServiceProductsConfig();

            config.ServiceURL = serviceURL;
            // Set other client connection configurations here if needed
            // Create the client itself
            MarketplaceWebServiceProducts client = new MarketplaceWebServiceProductsClient(appName, appVersion, accessKey, secretKey, config);

            MarketplaceWebServiceProductsSample sample = new MarketplaceWebServiceProductsSample(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;
                // response = sample.InvokeGetCompetitivePricingForASIN();
                // response = sample.InvokeGetCompetitivePricingForSKU();
                // response = sample.InvokeGetLowestOfferListingsForASIN();
                // response = sample.InvokeGetLowestOfferListingsForSKU();
                // response = sample.InvokeGetLowestPricedOffersForASIN();
                // response = sample.InvokeGetLowestPricedOffersForSKU();
                // response = sample.InvokeGetMatchingProduct();
                // response = sample.InvokeGetMatchingProductForId();
                // response = sample.InvokeGetMyFeesEstimate();
                // response = sample.InvokeGetMyPriceForASIN();
                // response = sample.InvokeGetMyPriceForSKU();
                // response = sample.InvokeGetProductCategoriesForASIN();
                // response = sample.InvokeGetProductCategoriesForSKU();
                //response = sample.InvokeGetServiceStatus();
                // response = sample.InvokeListMatchingProducts();
                Console.WriteLine("Response:");
                ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata;
                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                string responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (MarketplaceWebServiceProductsException ex)
            {
                // Exception properties are important for diagnostics.
                ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata;
                Console.WriteLine("Service Exception:");
                if (rhmd != null)
                {
                    Console.WriteLine("RequestId: " + rhmd.RequestId);
                    Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                }
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("StatusCode: " + ex.StatusCode);
                Console.WriteLine("ErrorCode: " + ex.ErrorCode);
                Console.WriteLine("ErrorType: " + ex.ErrorType);
                throw ex;
            }
        }
 public MWSMerchantFulfillmentServiceException(string message, HttpStatusCode statusCode, ResponseHeaderMetadata rhmd)
     : base((int)statusCode, message, null, null, null, rhmd)
 {
 }
コード例 #9
0
        public static void Main(string[] args)
        {
            // TODO: Set the below configuration variables before attempting to run

            // Developer AWS access key
            string accessKey = "AKIAJTIETNNID4BMNRTA";

            // Developer AWS secret key
            string secretKey = "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";

            // The client application name
            string appName = "CSharpSampleCode";

            // The client application version
            string appVersion = "1.0";

            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            string serviceURL = "https://mws.amazonservices.com";

            // Create a configuration object
            MarketplaceWebServiceSellersConfig config = new MarketplaceWebServiceSellersConfig();

            config.ServiceURL = serviceURL;
            // Set other client connection configurations here if needed
            // Create the client itself
            Claytondus.AmazonMWS.Sellers.MarketplaceWebServiceSellers client = new MarketplaceWebServiceSellersClient(appName, appVersion, accessKey, secretKey, config);

            MarketplaceWebServiceSellersSample sample = new MarketplaceWebServiceSellersSample(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;
                // response = sample.InvokeGetServiceStatus();
                response = sample.InvokeListMarketplaceParticipations();
                // response = sample.InvokeListMarketplaceParticipationsByNextToken();
                Console.WriteLine("Response:");
                ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata;
                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                string responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (MarketplaceWebServiceSellersException ex)
            {
                // Exception properties are important for diagnostics.
                ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata;
                Console.WriteLine("Service Exception:");
                if (rhmd != null)
                {
                    Console.WriteLine("RequestId: " + rhmd.RequestId);
                    Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                }
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("StatusCode: " + ex.StatusCode);
                Console.WriteLine("ErrorCode: " + ex.ErrorCode);
                Console.WriteLine("ErrorType: " + ex.ErrorType);
                throw ex;
            }
        }
コード例 #10
0
 /// <summary>
 /// Constructs MarketplaceWebServiceException with information available from service
 /// </summary>
 /// <param name="message">Overview of error</param>
 /// <param name="statusCode">HTTP status code for error response</param>
 /// <param name="errorCode">Error Code returned by the service</param>
 /// <param name="errorType">Error type. Possible types:  Sender, Receiver or Unknown</param>
 /// <param name="requestId">Request ID returned by the service</param>
 /// <param name="xml">Compete xml found in response</param>
 /// <param name="rhm">Response Header Metadata</param>
 public MarketplaceWebServiceException(String message, HttpStatusCode statusCode, String errorCode, String errorType, String requestId, String xml, ResponseHeaderMetadata rhm) : this(message, statusCode, rhm)
 {
     this.errorCode = errorCode;
     this.errorType = errorType;
     this.requestId = requestId;
     this.xml       = xml;
     this.responseHeaderMetadata = rhm;
 }
コード例 #11
0
 /// <summary>
 /// Constructs MarketplaceWebServiceException with message and status code
 /// </summary>
 /// <param name="message">Overview of error</param>
 /// <param name="statusCode">HTTP status code for error response</param>
 /// <param name="rhm">Response Header Metadata</param>
 public MarketplaceWebServiceException(String message, HttpStatusCode statusCode, ResponseHeaderMetadata rhm) : this(message)
 {
     this.statusCode             = statusCode;
     this.responseHeaderMetadata = rhm;
 }
        public static void Main(string[] args)
        {
            var            chain = new CredentialProfileStoreChain();
            AWSCredentials awsCredentials;

            chain.TryGetAWSCredentials("DD MWS", out awsCredentials);
            var creds = awsCredentials.GetCredentials();


            // Developer AWS access key
            string accessKey = creds.AccessKey;

            // Developer AWS secret key
            string secretKey = creds.SecretKey;

            // The client application name
            string appName = "CSharpSampleCode";

            // The client application version
            string appVersion = "1.0";

            string sellerId      = "ARA1ZW7ZHL5MQ";
            string marketplaceId = "ATVPDKIKX0DER";
            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            string serviceURL = "https://mws.amazonservices.com";

            // Create a configuration object
            MWSSubscriptionsServiceConfig config = new MWSSubscriptionsServiceConfig();

            config.ServiceURL = serviceURL;
            // Set other client connection configurations here if needed
            // Create the client itself
            MWSSubscriptionsService client = new MWSSubscriptionsServiceClient(accessKey, secretKey, appName, appVersion, config);

            MWSSubscriptionsServiceSample sample = new MWSSubscriptionsServiceSample(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;
                // response = sample.InvokeCreateSubscription();
                // response = sample.InvokeDeleteSubscription();

                // succesfully called
                //response = sample.InvokeRegisterDestination();
                //RegisterDestinationResponse registerDestinationResponse = (RegisterDestinationResponse)response;
                response = sample.InvokeCreateSubscription();
                CreateSubscriptionResponse createSubscriptionResponse = (CreateSubscriptionResponse)response;


                // response = sample.InvokeGetSubscription();
                //response = sample.InvokeListRegisteredDestinations();
                //response = sample.InvokeListSubscriptions();
                response = sample.InvokeRegisterDestination();
                //response = sample.InvokeSendTestNotificationToDestination();
                // response = sample.InvokeUpdateSubscription();
                // response = sample.InvokeGetServiceStatus();
                Console.WriteLine("Response:");
                ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata;
                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                string responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (MWSSubscriptionsServiceException ex)
            {
                // Exception properties are important for diagnostics.
                ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata;
                Console.WriteLine("Service Exception:");
                if (rhmd != null)
                {
                    Console.WriteLine("RequestId: " + rhmd.RequestId);
                    Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                }
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("StatusCode: " + ex.StatusCode);
                Console.WriteLine("ErrorCode: " + ex.ErrorCode);
                Console.WriteLine("ErrorType: " + ex.ErrorType);
                throw ex;
            }
        }