Esempio n. 1
0
        public async Task <byte[]> RenderReport(string report, ParameterValue[] parameters, string exportFormat = "PDF")
        {
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
            binding.MaxReceivedMessageSize = 100485760;

            var rsExec = new ReportExecutionServiceSoapClient(binding, new EndpointAddress(url));

            var clientCredentials = new NetworkCredential(userName, password);

            rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            rsExec.ClientCredentials.Windows.ClientCredential          = clientCredentials;

            TrustedUserHeader trustedUserHeader = new TrustedUserHeader();

            LoadReportResponse taskLoadReport = null;
            string             historyID      = null;

            taskLoadReport = await rsExec.LoadReportAsync(trustedUserHeader, report, historyID);

            ExecutionHeader executionHeader = new ExecutionHeader
            {
                ExecutionID = taskLoadReport.executionInfo.ExecutionID
            };

            await rsExec.SetExecutionParametersAsync(executionHeader, trustedUserHeader, parameters, null);

            const string   deviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";
            RenderResponse response   = await rsExec.RenderAsync(new RenderRequest(executionHeader, trustedUserHeader, exportFormat ?? "PDF", deviceInfo));

            return(response.Result);
        }
Esempio n. 2
0
        private async Task <LoadReportResponse> LoadReport(ReportExecutionServiceSoapClient rs, TrustedUserHeader trustedHeader, string reportPath)
        {
            // Get the report and set the execution header.
            // Failure to set the execution header will result in this error: "The session identifier is missing. A session identifier is required for this operation."
            // See https://social.msdn.microsoft.com/Forums/sqlserver/en-US/17199edb-5c63-4815-8f86-917f09809504/executionheadervalue-missing-from-reportexecutionservicesoapclient
            LoadReportResponse loadResponse = await rs.LoadReportAsync(trustedHeader, reportPath, HistoryId);

            return(loadResponse);
        }
Esempio n. 3
0
 public async Task TestAsync()
 {
     try
     {
         var trustedUserHeader = new TrustedUserHeader();
         var reportPath        = "replace with path to report in SSRS";
         var report            = await _reportClient.LoadReportAsync(trustedUserHeader, reportPath, null);
     }
     catch (Exception ex)
     {
         Console.WriteLine($"An excpetion occurred: {ex.Message}");
         throw;
     }
 }
        public async static Task <byte[]> GenerateSSRSReport(string County)
        {
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
            //binding.MaxReceivedMessageSize = 10485760; //10MB limit

            //Create the execution service SOAP Client
            var rsExec = new ReportExecutionServiceSoapClient(binding, new EndpointAddress(SSRSReportExecutionUrl));

            //Setup access credentials.
            var clientCredentials = new NetworkCredential(SSRSUsername, SSRSPassword, SSRSDomain);

            if (rsExec.ClientCredentials != null)
            {
                rsExec.ClientCredentials.Windows.AllowedImpersonationLevel =
                    System.Security.Principal.TokenImpersonationLevel.Impersonation;
                rsExec.ClientCredentials.Windows.ClientCredential = clientCredentials;
            }

            //This handles the problem of "Missing session identifier"
            rsExec.Endpoint.EndpointBehaviors.Add(new ReportingServicesEndpointBehavior());

            await rsExec.LoadReportAsync(null, "/" + SSRSFolderPath + "/" + ReportName, null);

            //TODO: determine parameters
            //Set the parameters asked for by the report
            ReportExecutionService.ParameterValue[] reportParam = new ReportExecutionService.ParameterValue[1];

            reportParam[0]       = new ReportExecutionService.ParameterValue();
            reportParam[0].Name  = "County";
            reportParam[0].Value = County.ToString();

            await rsExec.SetExecutionParametersAsync(null, null, reportParam, "en-us");

            //run the report
            const string deviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
            var          response   = await rsExec.RenderAsync(new RenderRequest(null, null, "PDF", deviceInfo));

            //spit out the result
            var byteResults = response.Result;

            return(byteResults);
        }
Esempio n. 5
0
        public async Task <byte[]> RenderReport(string reportPath, IDictionary <string, string> parameters, ExportFormat exportFormat, string fileName)
        {
            byte[] fileContent = null;
            try
            {
                //My binding setup, since ASP.NET Core apps don't use a web.config file
                var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
                binding.MaxReceivedMessageSize = 10485760; //I wanted a 10MB size limit on response to allow for larger PDFs

                string _reportingServicesUrl = _config["WCFExternalServices:ReportingService:EndpointAddress"];

                //Create the execution service SOAP Client
                var rsExec = new ReportExecutionServiceSoapClient(binding, new EndpointAddress(_reportingServicesUrl));

                //Setup access credentials. I use windows credentials, yours may differ
                var clientCredentials = new NetworkCredential();
                //rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                rsExec.ClientCredentials.Windows.ClientCredential = clientCredentials;

                //This handles the problem of "Missing session identifier"
                rsExec.Endpoint.EndpointBehaviors.Add(new ReportingServicesEndpointBehavior());

                string            historyID         = null;
                TrustedUserHeader trustedUserHeader = new TrustedUserHeader();
                ExecutionHeader   execHeader        = new ExecutionHeader();

                trustedUserHeader.UserName = clientCredentials.UserName;

                //Load the report
                var taskLoadReport = await rsExec.LoadReportAsync(trustedUserHeader, reportPath, historyID);

                // Fixed the exception of "session identifier is missing".
                execHeader.ExecutionID = taskLoadReport.executionInfo.ExecutionID;

                //
                //Set the parameteres asked for by the report
                //

                string lang = "";

                if (fileName == "LoanStatement" || fileName == "Payment_order" || fileName == "CreditLineStatement")
                {
                    if (Convert.ToInt32(parameters["lang_id"]) == 1)
                    {
                        lang = "hy-am";
                    }
                    else
                    {
                        lang = "en-us";
                    }
                }
                else
                {
                    lang = "en-us";
                }

                ParameterValue[] reportParameters = null;
                if (parameters != null && parameters.Count > 0)
                {
                    reportParameters = taskLoadReport.executionInfo.Parameters.Where(x => parameters.ContainsKey(x.Name)).Select(x => new ParameterValue()
                    {
                        Name = x.Name, Value = parameters[x.Name] != null ? parameters[x.Name].ToString() : null
                    }).ToArray();
                }
                await rsExec.SetExecutionParametersAsync(execHeader, trustedUserHeader, reportParameters, lang);

                //run the report
                string format = GetExportFormatString(exportFormat);
                // run the report
                const string deviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

                var response = await rsExec.RenderAsync(new RenderRequest(execHeader, trustedUserHeader, format, deviceInfo));

                //spit out the result
                return(response.Result);
            }
            catch (Exception ex)
            {
                // System.Web.HttpContext.Current.Response.BufferOutput = true;
                //   System.Web.HttpContext.Current.Response.TrySkipIisCustomErrors = true;
                //  System.Web.HttpContext.Current.Response.StatusCode = 422;
                //  System.Web.HttpContext.Current.Response.StatusDescription = Utils.ConvertAnsiToUnicode(ex.Message);
                throw ex;
            }
            return(fileContent);
        }
        private async Task <byte[]> RenderReport(string reportName, IDictionary <string, object> parameters, string languageCode, string exportFormat)
        {
            const string SSRSUsername           = "******";
            const string SSRSDomain             = "DESKTOP-FFAAKTS";
            const string SSRSPassword           = "******";
            const string SSRSReportExecutionUrl = "http://desktop-ffaakts/ReportServer/ReportExecution2005.asmx";
            const string SSRSFolderPath         = "DemoReports";
            string       reportPath             = string.Format("{0}{1}", SSRSFolderPath, reportName);

            //
            // Binding setup, since ASP.NET Core apps don't use a web.config file
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.None);

            //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
            binding.MaxReceivedMessageSize = 999999999; //10MB limit
            binding.MaxBufferSize          = 999999999;
            binding.OpenTimeout            = new TimeSpan(0, 90, 0);
            binding.CloseTimeout           = new TimeSpan(0, 90, 0);
            binding.SendTimeout            = new TimeSpan(0, 90, 0);
            binding.ReceiveTimeout         = new TimeSpan(0, 90, 0);

            //Create the execution service SOAP Client
            ReportExecutionServiceSoapClient reportClient = new ReportExecutionServiceSoapClient(binding, new EndpointAddress(SSRSReportExecutionUrl));

            //Setup access credentials. Here use windows credentials.
            var clientCredentials = new NetworkCredential(SSRSUsername, SSRSPassword, SSRSDomain);

            reportClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            reportClient.ClientCredentials.Windows.ClientCredential          = clientCredentials;

            //This handles the problem of "Missing session identifier"
            reportClient.Endpoint.EndpointBehaviors.Add(new ReportingServiceEndPointBehavior());

            //string historyID = null;
            //TrustedUserHeader trustedUserHeader = new TrustedUserHeader();
            //ExecutionHeader execHeader = new ExecutionHeader();

            //trustedUserHeader.UserName = clientCredentials.UserName;

            //
            // Load the report
            //
            var taskLoadReport = await reportClient.LoadReportAsync(null, "/" + SSRSFolderPath + "/" + reportName, null);

            // Fixed the exception of "session identifier is missing".
            reportClient.Endpoint.EndpointBehaviors.Add(new ReportingServicesEndpointBehavior());

            //
            //Set the parameteres asked for by the report
            //
            ParameterValue[] reportParameters = null;
            if (parameters != null && parameters.Count > 0)
            {
                reportParameters = taskLoadReport.executionInfo.Parameters.Where(x => parameters.ContainsKey(x.Name)).Select(x => new ParameterValue()
                {
                    Name = x.Name, Value = parameters[x.Name].ToString()
                }).ToArray();
            }

            await reportClient.SetExecutionParametersAsync(null, null, reportParameters, languageCode);

            // run the report
            const string deviceInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

            var response = await reportClient.RenderAsync(new RenderRequest(null, null, exportFormat ?? exportFormat, deviceInfo));

            //spit out the result
            return(response.Result);
        }