/// <summary> /// The GetReport operation returns the contents of a report. Reports can potentially be /// very large (>100MB) which is why we only return one report at a time, and in a /// streaming fashion. /// /// </summary> /// <param name="service">Instance of MarketplaceWebService service</param> /// <param name="request">GetReportRequest request</param> public static void InvokeGetReport(MarketplaceWebService service, GetReportRequest request) { try { GetReportResponse response = service.GetReport(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" GetReportResponse"); if (response.IsSetGetReportResult()) { Console.WriteLine(" GetReportResult"); GetReportResult getReportResult = response.GetReportResult; if (getReportResult.IsSetContentMD5()) { Console.WriteLine(" ContentMD5"); Console.WriteLine(" {0}", getReportResult.ContentMD5); } } 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); } }
/** * Samples for Marketplace Web Service functionality */ public static void GetReport(string reportType, string fileName) { /************************************************************************ * 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. ***********************************************************************/ /************************************************************************ * All MWS requests must contain the seller's merchant ID and * marketplace ID. ***********************************************************************/ 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); //*** 1. Submit a report request using the RequestReport operation. This is a request to Amazon MWS to generate a specific report. RequestReportRequest reportRequest = new RequestReportRequest(); reportRequest.Merchant = GlobalConfig.Instance.SellerId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional reportRequest.MarketplaceIdList = new IdList(); reportRequest.MarketplaceIdList.Id = new List<string>( new string [] { GlobalConfig.Instance.MarketplaceId } ); reportRequest.ReportType = reportType; reportRequest.StartDate = new DateTime(2015, 8, 1); reportRequest.EndDate = new DateTime(2015, 9, 21); // @TODO: set additional request parameters here // request.ReportOptions = "ShowSalesChannel=true"; string reportRequestId = RequestReportSample.InvokeRequestReport(service, reportRequest); Dictionary<string, string> requestInfo = new Dictionary<string, string>(); requestInfo["ReportProcessingStatus"] = ""; requestInfo["GeneratedReportId"] = ""; /************************************************************************ * Uncomment to invoke Get Report Request List Action ***********************************************************************/ { GetReportRequestListRequest request = new GetReportRequestListRequest(); request.Merchant = GlobalConfig.Instance.SellerId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here request.ReportRequestIdList = new IdList(); request.ReportRequestIdList.Id = new List<string>(new string[] { reportRequestId }); while(requestInfo["ReportProcessingStatus"] != "_DONE_" && requestInfo["GeneratedReportId"] == "") { if(!GetReportRequestListSample.InvokeGetReportRequestList(service, request, requestInfo)) { // todo �쳣���� } //*** Request every 60s System.Threading.Thread.Sleep(1 * 60 * 1000); } } //*** 2. Using the GetReportList operation and include the ReportRequestId for the report requested. //*** The operation returns a ReportId that you can then pass to the GetReport operation 50193016685 { if (requestInfo["ReportProcessingStatus"] == "_DONE_" && requestInfo["GeneratedReportId"] == "") { GetReportListRequest getReportListRequest = new GetReportListRequest(); getReportListRequest.Merchant = GlobalConfig.Instance.SellerId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional getReportListRequest.ReportRequestIdList = new IdList(); getReportListRequest.ReportRequestIdList.Id = new List<string>(new string[] { reportRequestId }); string reportId = ""; while (reportId == "") { //*** Request every 60s System.Threading.Thread.Sleep(1 * 60 * 1000); reportId = GetReportListSample.InvokeGetReportList(service, getReportListRequest); } requestInfo["reportId"] = reportId; } } //*** 3. Submit a request using the GetReport operation to receive a specific report. //*** You include in the request the GeneratedReportId or the ReportId for the report you want to receive. //*** You then process the Content-MD5 header to confirm that the report was not corrupted during transmission. GetReportRequest getReportRequest = new GetReportRequest(); getReportRequest.Merchant = GlobalConfig.Instance.SellerId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // Note that depending on the type of report being downloaded, a report can reach // sizes greater than 1GB. For this reason we recommend that you _always_ program to // MWS in a streaming fashion. Otherwise, as your business grows you may silently reach // the in-memory size limit and have to re-work your solution. // NOTE: Due to Content-MD5 validation, the stream must be read/write. if (requestInfo["GeneratedReportId"] != "" || requestInfo["reportId"] != "") { getReportRequest.ReportId = requestInfo["GeneratedReportId"] != "" ? requestInfo["GeneratedReportId"] : requestInfo["reportId"]; getReportRequest.Report = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); GetReportSample.InvokeGetReport(service, getReportRequest); getReportRequest.Report.Close(); } }
private void DownloadDoneReportAndAddnewCustomHeader() { ProcessingLog.LogAndPrintScreenMessage(string.Format("Request to download report with Report Id {0}", _amzDownloadedReportId), true); GetReportRequest getReportRequest = new GetReportRequest { Merchant = _merchant, ReportId = _amzDownloadedReportId }; using (var reportSteam = File.Open(_downloadedReportPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { getReportRequest.Report = reportSteam; //The returned md5 header is compared and if not match it will throw - not going to retry as it could mean bigger problems GetReportResponse getReportResponse = _marketplaceWebService.GetReport(getReportRequest); ProcessingLog.LogAndPrintScreenMessage(string.Format("Downloaded report has Content MD5: {0}", getReportResponse.GetReportResult.ContentMD5), true); } if (!File.Exists(_downloadedReportPath)) { throw new ApplicationException(string.Format("ERROR cannot find downloaded report at: {0}", _downloadedReportPath)); } }