コード例 #1
0
        private static void Test()
        {
            var config = new MarketplaceWebServiceConfig();

            config.SetUserAgentHeader( "", "", "C#" );

            config.ServiceURL = "https://mws.amazonservices.com";

            MarketplaceWebService service = new MarketplaceWebServiceClient(
                Secret.AwsAccessKeyId,
                Secret.AwsSecretAccessKey,
                config );

            var request = new SubmitFeedRequest {
                Merchant = Secret.MerchantId,
                MWSAuthToken = null,//"",
                MarketplaceIdList = new IdList { Id = new List< string >( new string[] { Secret.MarketplaceId } ) },
                FeedContent = File.Open( Filename, FileMode.Open, FileAccess.Read ),
                FeedType = FeedType
            };
            request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5( request.FeedContent );
            request.FeedContent.Position = 0;

            SubmitFeedSample.InvokeSubmitFeed( service, request );
        }
コード例 #2
0
 /// <summary>
 /// Creates the SubmitFeedRequest given a stream of content
 /// </summary>
 /// <param name="dataContent">The stream of the content</param>
 /// <param name="feedType">The type of feed to be submitted.</param>
 /// <returns>A SubmitFeedRequest object</returns>
 private SubmitFeedRequest CreateSubmitFeedRequest(Stream dataContent, string feedType)
 {
     var request = new SubmitFeedRequest();
     request.Merchant = _MerchantId;
     request.MarketplaceIdList = new IdList();
     request.MarketplaceIdList.Id = new List<string>(new string[] { _MarketplaceId });
     request.FeedContent = dataContent;
     // Set the MD5 hash of the content
     request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
     // Reset the position of the reader of the FeedContent
     request.FeedType = feedType;
     return request;
 }
コード例 #3
0
ファイル: AmazonApiService.cs プロジェクト: neozhu/Ecommerce
 public SubmitFeedRequest GetSubmitFeedRequest(AmazonFeedType feedType, FileStream feedContent)
 {
     var request = new SubmitFeedRequest()
     {
         Merchant = _amazonSellerSettings.SellerId,
         ContentType = new ContentType(MediaType.XML),
         FeedContent = feedContent,
         FeedType = feedType.ToString(),
         MarketplaceIdList = new IdList { Id = new List<string>(new[] { _amazonSellerSettings.MarketplaceId }) }
     };
     request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
     return request;
 }
コード例 #4
0
        public static SubmitFeedResponse SendAmazonFeeds(IMarketplaceWebServiceClient feedService, IEnumerable<Product> amazonUpdateList, AmazonEnvelopeMessageType messageType, AmazonFeedType feedType, string AmazonMerchantId, string AmazonMarketplaceId, string AmazonServiceUrl, string AmazonAccessKeyId, string AmazonSecretAccessKey)
        {
            //var requestResponse = new List<string>();
            SubmitFeedResponse feedResponse = null;

            var amazonEnvelope = new AmazonEnvelope { Header = new Header { DocumentVersion = "1.01", MerchantIdentifier = AmazonMerchantId, }, MessageType = messageType };
            var updates = new List<AmazonEnvelopeMessage>();
            var counter = 1;
            foreach (var amazonUpdate in amazonUpdateList)
            {
                var curUpdate = new AmazonEnvelopeMessage { MessageID = counter.ToString(), Item = amazonUpdate };
                updates.Add(curUpdate);
                counter++;
            }

            //add all update products to envelope's message
            amazonEnvelope.Message = updates.ToArray();

            var serializer = new XmlSerializer(amazonEnvelope.GetType());

            var stringReader = new StringWriter();
            serializer.Serialize(stringReader, amazonEnvelope);
            var xmlResult = stringReader.ToString();

            using (MemoryStream feedStream = new MemoryStream())
            {
                serializer.Serialize(feedStream, amazonEnvelope);

                var feedRequest = new SubmitFeedRequest
                {
                    Merchant = AmazonMerchantId,
                    MarketplaceIdList = new IdList { Id = new List<string>(new[] { AmazonMarketplaceId }) },
                    FeedType = feedType.ToString(),
                    ContentType = new ContentType(MediaType.OctetStream),
                    FeedContent = feedStream
                };

                // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the
                // position, or create another stream for the calculation.
                feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent);

                //var feedService = new MockMarketplaceWebServiceClient();

                var uploadSuccess = false;
                var retryCount = 0;

                while (!uploadSuccess)
                {
                    try
                    {
                        feedResponse = feedService.SubmitFeed(feedRequest);
                        //var submissionId = feedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId;
                        //requestResponse.Add(submissionId);
                        uploadSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        //if sending not succeed after 3 attempts stop retrying
                        retryCount++;
                        if (retryCount == 3) break;

                        //pause sending for 3 minutes
                        Thread.Sleep(18000);
                        if (ex.ToString().ToLowerInvariant().Contains("request is throttled")) continue;
                        //requestResponse.Add(string.Format("ERROR: {0}", ex));
                    }
                }
            }

            return feedResponse;
        }
コード例 #5
0
ファイル: SubmitFeedSample.cs プロジェクト: six006/spreadbot
        /// <summary>
        /// Uploads a file for processing together with the necessary
        /// metadata to process the file, such as which type of feed it is.
        /// PurgeAndReplace if true means that your existing e.g. inventory is
        /// wiped out and replace with the contents of this feed - use with
        /// caution (the default is false).
        /// 
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">SubmitFeedRequest request</param>
        public static void InvokeSubmitFeed(MarketplaceWebService service, SubmitFeedRequest request)
        {
            try
            {
                SubmitFeedResponse response = service.SubmitFeed(request);

                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        SubmitFeedResponse");
                if (response.IsSetSubmitFeedResult())
                {
                    Console.WriteLine("            SubmitFeedResult");
                    SubmitFeedResult  submitFeedResult = response.SubmitFeedResult;
                    if (submitFeedResult.IsSetFeedSubmissionInfo())
                    {
                        Console.WriteLine("                FeedSubmissionInfo");
                        FeedSubmissionInfo  feedSubmissionInfo = submitFeedResult.FeedSubmissionInfo;
                        if (feedSubmissionInfo.IsSetFeedSubmissionId())
                        {
                            Console.WriteLine("                    FeedSubmissionId");
                            Console.WriteLine("                        {0}", feedSubmissionInfo.FeedSubmissionId);
                        }
                        if (feedSubmissionInfo.IsSetFeedType())
                        {
                            Console.WriteLine("                    FeedType");
                            Console.WriteLine("                        {0}", feedSubmissionInfo.FeedType);
                        }
                        if (feedSubmissionInfo.IsSetSubmittedDate())
                        {
                            Console.WriteLine("                    SubmittedDate");
                            Console.WriteLine("                        {0}", feedSubmissionInfo.SubmittedDate);
                        }
                        if (feedSubmissionInfo.IsSetFeedProcessingStatus())
                        {
                            Console.WriteLine("                    FeedProcessingStatus");
                            Console.WriteLine("                        {0}", feedSubmissionInfo.FeedProcessingStatus);
                        }
                        if (feedSubmissionInfo.IsSetStartedProcessingDate())
                        {
                            Console.WriteLine("                    StartedProcessingDate");
                            Console.WriteLine("                        {0}", feedSubmissionInfo.StartedProcessingDate);
                        }
                        if (feedSubmissionInfo.IsSetCompletedProcessingDate())
                        {
                            Console.WriteLine("                    CompletedProcessingDate");
                            Console.WriteLine("                        {0}", feedSubmissionInfo.CompletedProcessingDate);
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata  responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }

                Console.WriteLine("            ResponseHeaderMetadata");
                Console.WriteLine("                RequestId");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.RequestId);
                Console.WriteLine("                ResponseContext");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.ResponseContext);
                Console.WriteLine("                Timestamp");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.Timestamp);

            }
            catch (MarketplaceWebServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }
コード例 #6
0
        public static void SubmitFeed(string fileName, string feedType)
        {
            //IniReader iniReader = new IniReader(System.Environment.CurrentDirectory + "\\config.ini");
            //string awsSection = "AWS_US";

            //String accessKeyId = iniReader.ReadValue(awsSection, "accessKey");
            //String secretAccessKey = iniReader.ReadValue(awsSection, "secretKey");

            /************************************************************************
            * Instantiate  Implementation of Marketplace Web Service
            ***********************************************************************/

            MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();

            /************************************************************************
             * The application name and version are included in each MWS call's
             * HTTP User-Agent field. These are required fields.
             ***********************************************************************/

            //string applicationName = iniReader.ReadValue(awsSection, "appName"); ;
            //string applicationVersion = iniReader.ReadValue(awsSection, "appVersion");

            /************************************************************************
             * All MWS requests must contain the seller's merchant ID and
             * marketplace ID.
             ***********************************************************************/
            //string merchantId = iniReader.ReadValue(awsSection, "sellerId");
            //string marketplaceId = iniReader.ReadValue(awsSection, "marketplaceId");

            // United States:
            config.ServiceURL = GlobalConfig.Instance.ServiceURL;

            config.SetUserAgentHeader(GlobalConfig.Instance.AppName, GlobalConfig.Instance.AppVersion, "C#");

            MarketplaceWebService service = new MarketplaceWebServiceClient(GlobalConfig.Instance.AccessKey, GlobalConfig.Instance.SecretKey, config);

            SubmitFeedRequest request = new SubmitFeedRequest();
            request.Merchant = GlobalConfig.Instance.SellerId;
            // request.MWSAuthToken = iniReader.ReadValue(awsSection, "MWSAuthToken"); // Optional
            request.MarketplaceIdList = new IdList();
            request.MarketplaceIdList.Id = new List<string>(new string[] { GlobalConfig.Instance.MarketplaceId });

            // MWS exclusively offers a streaming interface for uploading your feeds. This is because
            // feed sizes can grow to the 1GB+ range - and as your business grows you could otherwise
            // silently reach the feed size where your in-memory solution will no longer work, leaving you
            // puzzled as to why a solution that worked for a long time suddenly stopped working though
            // you made no changes. For the same reason, we strongly encourage you to generate your feeds to
            // local disk then upload them directly from disk to MWS.

            request.FeedContent = File.Open(fileName, FileMode.Open, FileAccess.Read);

            // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the
            // position, or create another stream for the calculation.
            request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
            request.FeedContent.Position = 0;

            request.FeedType = feedType;

            SubmitFeedSample.InvokeSubmitFeed(service, request);
            request.FeedContent.Close();
        }