/// <summary>
 /// step 2.
 /// </summary>
 protected void SetParameters(ReportRequest rRequest, ReportExecuteResult result)
 {
     if (result.ParametersRequired && rRequest.Parameters.Count == 0)
     {
         throw new ReportException("The report parameters is required.");
     }
     try
     {
         var paramenters = rRequest.Parameters.Select(t => new ParameterValue {
             Name = t.Key, Value = t.Value
         }).ToArray();
         var request  = new SetExecutionParametersRequest(paramenters, "en-us");
         var response = ReportClient.SetExecutionParametersAsync(request).GetAwaiter().GetResult();
         result.SessionId = rRequest.SessionId = response.executionInfo.ExecutionID;
     }
     catch (Exception ex)
     {
         throw new ReportException("SetParameters error: " + ex.Message, ex);
     }
 }
        public async Task <IActionResult> MovieSellersReport(int movieId)
        {
            var reportName = "MovieSellers";
            //Render a PDF of the sellers for the given movie

            //
            //Configure Report Proxy
            //
            var ssrsClient = getSSRS2005ExecClient();

            try
            {
                await ssrsClient.OpenAsync();

                var ssrsSettings = _config.GetSection("SSRS");

                //
                //Load report
                //
                var loadRequest = new LoadReportRequest();
                loadRequest.Report = string.Format("/{0}/{1}", ssrsSettings["ReportsFolder"].Trim('/'), reportName);
                var loadResponse = await ssrsClient.LoadReportAsync(loadRequest);

                //
                //Setup Parameters
                //
                // this report has one parameter, the MovieId
                var reportParams = new ParameterValue[] { new ParameterValue()
                                                          {
                                                              Name = "MovieId", Value = movieId.ToString()
                                                          } };
                //Note, if you have a parameter that is optional, still include it but set its value to null
                var ssrsParamRequest = new SetExecutionParametersRequest();
                ssrsParamRequest.ExecutionHeader   = loadResponse.ExecutionHeader;
                ssrsParamRequest.Parameters        = reportParams;
                ssrsParamRequest.ParameterLanguage = "en-us";
                var setParamResponse = await ssrsClient.SetExecutionParametersAsync(ssrsParamRequest);

                //
                //Render Report
                //
                var renderRequest  = new RenderRequest(loadResponse.ExecutionHeader, null, "PDF", null);
                var renderResponse = await ssrsClient.RenderAsync(renderRequest);

                var returnedReport = renderResponse.Result;
                await ssrsClient.CloseAsync();

                //Send report to user
                if (returnedReport != null)
                {
                    //return report to client. Browser handler will show (in edge, this will show automatically in browser) OR, if no browser handler for PDF, report will show up as a download.
                    return(new FileContentResult(returnedReport, "application/pdf"));
                }
                else
                {
                    //Error rendering the report.
                    ViewBag.ErrorMessage = "The report failed to render. Check the report server.";
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }
            finally
            {
                if (ssrsClient.State != CommunicationState.Closed)
                {
                    ssrsClient.Abort();
                }
            }

            return(RedirectToAction("ErrorUserFacing", "Home", new { errorMessage = ViewBag.ErrorMessage }));
        }