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); }
public ExampleRun(IConfiguration configuration) { _reportClient = new ReportExecutionServiceSoapClient(new BasicHttpBinding() { MaxReceivedMessageSize = MaxReceivedMessageSize, }, new EndpointAddress(configuration["ReportExecutionServiceSoapUrl"])); _reportClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; }
public ReportOutput Execute() { ExecutionInfo executionInfo; List <ParameterValue> parameterValues = new List <ParameterValue>(); TrustedUserHeader trustedUserHeader = null; ServerInfoHeader serverInfoHeader; ExecutionHeader executionHeader; byte[] result; string extension; string mimeType; string encoding; Warning[] warnings = { }; string[] streamIds; // Build client _client = new ReportExecutionServiceSoapClient(new BasicHttpBinding(), new EndpointAddress(this.ReportServerUrl)); // Set credentials _client.ClientCredentials.Windows.ClientCredential = this.Credential; _client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; // Load the report executionHeader = _client.LoadReport(trustedUserHeader, this.Report, this.HistoryId, out serverInfoHeader, out executionInfo); // Map the parameters foreach (KeyValuePair <string, string> parameter in this.Parameters) { parameterValues.Add(new ParameterValue() { Name = parameter.Key, Value = parameter.Value }); } // Set the execution parameters if (parameterValues.Count > 0) { serverInfoHeader = _client.SetExecutionParameters(executionHeader, trustedUserHeader, parameterValues.ToArray(), null, out executionInfo); } // Render the report serverInfoHeader = _client.Render(executionHeader, trustedUserHeader, this.Format, this.DeviceInfo, out result, out extension, out mimeType, out encoding, out warnings, out streamIds); // Build output object return(new ReportOutput() { ExecutionInfo = executionInfo, Result = result, Extension = extension, MimeType = mimeType, Encoding = encoding, Warnings = warnings, StreamIds = streamIds }); }
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); }
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); }
private ReportExecutionServiceSoapClient CreateExecutionClient(string reportExecution2005EndPointUrl) { BasicHttpsBinding rsBinding = new BasicHttpsBinding(); rsBinding.Security.Mode = BasicHttpsSecurityMode.Transport; rsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; // So we can download reports bigger than 64 KBytes // See https://stackoverflow.com/questions/884235/wcf-how-to-increase-message-size-quota rsBinding.MaxBufferPoolSize = 20000000; rsBinding.MaxBufferSize = 20000000; rsBinding.MaxReceivedMessageSize = 20000000; EndpointAddress rsEndpointAddress = new EndpointAddress(reportExecution2005EndPointUrl); ReportExecutionServiceSoapClient rsClient = new ReportExecutionServiceSoapClient(rsBinding, rsEndpointAddress); // Set user name and password rsClient.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; return(rsClient); }
public FileContentResult Index() { Dictionary <string, string> reportParameters = new Dictionary <string, string>(); Request.QueryString.AllKeys.Where(x => !x.Equals("ReportName")).ForEach(x => reportParameters.Add(x, Request.QueryString[x])); byte[] byteResult = new byte[0]; string extension, mimeType, encoding; Warning[] warnings = new Warning[0]; string[] streamIds = new string[0]; ServerInfoHeader serverInfoHeader; ExecutionInfo2 execInfo = new ExecutionInfo2(); ReportExecutionServiceSoapClient rsServiceClient = new ReportExecutionServiceSoapClient(); rsServiceClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; ExecutionHeader execHeader = rsServiceClient.LoadReport2(null, "/Axis.ReportDB/" + Request.QueryString["ReportName"], null, out serverInfoHeader, out execInfo); rsServiceClient.SetExecutionParameters2(execHeader, null, reportParameters.Select(x => new ParameterValue { Name = x.Key, Value = x.Value }).ToArray(), "en-us", out execInfo); string sessionId = execInfo.ExecutionID; try { serverInfoHeader = rsServiceClient.Render2(execHeader, null, "PDF", @"<DeviceInfo><Toolbar>True</Toolbar></DeviceInfo>", PageCountMode.Actual, out byteResult, out extension, out mimeType, out encoding, out warnings, out streamIds); } catch (Exception) { throw; } return(new FileContentResult(byteResult, "application/pdf")); }
public Report(string reportExecution2005EndPointUrl, string reportService2005EndPointUrl) { ReportParameters = new List <ReportExecution.ParameterValue>(); RSExecutionClient = CreateExecutionClient(reportExecution2005EndPointUrl); RSServiceClient = CreateServiceClient(reportService2005EndPointUrl); }
public ReportEndpointBehavior(ReportExecutionServiceSoapClient client) { inspector = new ReportClientMessageInspector(client); }
public ReportClientMessageInspector(ReportExecutionServiceSoapClient client) { this.client = client; }
public ReportExecutionContext(ReportExecutionServiceSoapClient client) { this.Client = client; }
public string RunReport(string path, string reportCode, Dictionary <string, string> dicParams) { var format = ""; var result = ""; try { DataSourceCredentials[] credentials = null; string encoding; string mimeType; string extension; Warning[] warnings = null; string[] streamIDs = null; string historyID = null; byte[] reportResult = null; var devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; var rs = new ReportExecutionServiceSoapClient(GetDefaultBinding(), new EndpointAddress(@"http://localhost:8282/ReportServer/ReportExecution2005.asmx")); rs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; rs.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; rs.ClientCredentials.UserName.UserName = "******"; rs.ClientCredentials.UserName.Password = "******"; // Render arguments var execInfo = new ExecutionInfo(); var execHeader = new ExecutionHeader(); var trustedHeader = new TrustedUserHeader(); var serverInfo = new ServerInfoHeader(); var path2 = "/" + path + "/" + reportCode; rs.LoadReport(trustedHeader, path2, historyID, out serverInfo, out execInfo); // Genera los parametros apartir de un diccionario var parameters = new ParameterValue[dicParams.Count]; var index = 0; foreach (var param in dicParams) { var paramValue = new ParameterValue { Name = param.Key, Value = param.Value }; parameters[index] = paramValue; index++; } execHeader.ExecutionID = execInfo.ExecutionID; rs.SetExecutionParameters(execHeader, trustedHeader, parameters, "en-us", out execInfo); //Invocacion del reporte format = "PDF"; rs.Render(execHeader, trustedHeader, format, devInfo, out reportResult, out extension, out mimeType, out encoding, out warnings, out streamIDs); result = Convert.ToBase64String(reportResult); } catch (Exception ex) { throw ex; } return(result); }
public object ReporteFormatoEtiquetasOrdenRecepcion(int ordenRecepcionID, Sam3_Usuario usuario) { try { #region parametros byte[] reporte; string historyID = null; string deviceInfo = null; string extension; string encoding; string mimeType; Warning[] warnings; string[] streamIDs = null; string format = "PDF"; string rutaReporte = "/Reportes/Formato de Etiquetas"; NetworkCredential credenciales = new NetworkCredential(usuarioReportes, passReportes); #endregion ReportExecutionServiceSoapClient cliente = new ReportExecutionServiceSoapClient(); cliente.ClientCredentials.Windows.ClientCredential = credenciales; cliente.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; cliente.ClientCredentials.UserName.UserName = usuarioReportes; cliente.ClientCredentials.UserName.Password = passReportes; ParameterValue[] parametros = new ParameterValue[1]; parametros[0] = new ParameterValue(); parametros[0].Name = "OrdenRecepcionID"; parametros[0].Value = ordenRecepcionID.ToString(); ExecutionInfo infoEjecucion = new ExecutionInfo(); TrustedUserHeader encabezadoSeguro = null; ExecutionHeader encabezadoDeEjecucion = new ExecutionHeader(); ServerInfoHeader encavezadoDeServidor = new ServerInfoHeader(); encabezadoDeEjecucion = cliente.LoadReport(encabezadoSeguro, rutaReporte, historyID, out encavezadoDeServidor, out infoEjecucion); cliente.SetExecutionParameters(encabezadoDeEjecucion, encabezadoSeguro, parametros, "en-US", out infoEjecucion); cliente.Render(encabezadoDeEjecucion, encabezadoSeguro, format, deviceInfo, out reporte, out extension, out mimeType, out encoding, out warnings, out streamIDs); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); Stream iStream = new MemoryStream(reporte); response.Content = new StreamContent(iStream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = "EtiquetasMaterial_" + ordenRecepcionID.ToString() + ".pdf"; return(response); } catch (Exception ex) { //-----------------Agregar mensaje al Log ----------------------------------------------- LoggerBd.Instance.EscribirLog(ex); //-----------------Agregar mensaje al Log ----------------------------------------------- TransactionalInformation result = new TransactionalInformation(); result.ReturnMessage.Add("Error al cargar el reporte"); result.ReturnCode = 500; result.ReturnStatus = false; result.IsAuthenicated = true; return(result); } }
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); }
public ValidatedResponse<string> RenderReport(ExecuteReportRequest reportRequest, string outputFolderPath) { if (string.IsNullOrEmpty(reportRequest.outputFilename)) { Log.Debug("RenderReport : Report outputFilename must not be null or empty"); return ValidatedResponseHelper.Failure<string>("Report OutputFilename must not be null or empty"); } Log.Information("RenderReport : [{@outputFilename}] Requesting report object {@reportName}", reportRequest.outputFilename, reportRequest.reportName); var reportExecutionWatch = Stopwatch.StartNew(); var parameters = this.GetParameters(reportRequest); var reportObject = this.GetReportObjectFromSSRS(reportRequest.reportName); if (!reportObject.IsSuccessful) { Log.Error("RenderReport : [{@outputFilename}] Error retrieve report {@reportName}", reportRequest.outputFilename, reportRequest.reportName); return ValidatedResponseHelper.Failure<string>("Error retrieve report {0} : {1}", reportRequest.reportName, reportObject.ValidationResults.AsString()); } var fileNameAndPath = string.Empty; try { var renderFormat = RenderFormat.FromValue(reportRequest.outputFormatType.ToString()); // also throws ArgumentException if can't be parsed // Set parameters into SoapClient object. var rsExec = new ReportExecutionServiceSoapClient(); rsExec.Endpoint.Address = this.reportExecution2005Reference; rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; rsExec.ClientCredentials.Windows.ClientCredential = null; Log.Debug("RenderReport : [{@outputFilename}] Loading report {@report}", reportRequest.outputFilename, reportObject.Result.Path); rsExec.LoadReport(this.trusteduserHeader, reportObject.Result.Path, null, out this.serviceInfo, out this.execInfo); Log.Debug("RenderReport : [{@outputFilename}] Report loaded {@report} with Execution ID {@executionID}", reportRequest.outputFilename, reportObject.Result.Path, this.execInfo.ExecutionID); this.execHeader.ExecutionID = this.execInfo.ExecutionID; // Set the parameters. rsExec.SetExecutionParameters(this.execHeader, this.trusteduserHeader, parameters, "EN-US", out this.execInfo); Log.Debug("RenderReport : [{@outputFilename}] Parameters {@param} was set.", reportRequest.outputFilename, parameters); byte[] result; string extension; string encoding; string mimeType; RE2005.Warning[] warnings; string[] streamIDs; Log.Debug("RenderReport : [{@outputFilename}] Rendering report...", reportRequest.outputFilename); // Render the report. rsExec.Render(this.execHeader, null, renderFormat.SSRSValue, null, out result, out extension, out mimeType, out encoding, out warnings, out streamIDs); Log.Debug("RenderReport : [{@outputFilename}] Saving report to file...", reportRequest.outputFilename); fileNameAndPath = this.fileWriter.WriteToFile(outputFolderPath, reportRequest.outputFilename, result); Log.Information("RenderReport : [{@outputFilename}] Report saved in {@filenameandPath}", reportRequest.outputFilename, fileNameAndPath); } catch (Exception ex) { Log.Error(ex, "RenderReport: Something went wrong {@stackTrace}", ex.ToString()); return ValidatedResponseHelper.Failure<string>("Error {0}", ex.ToString()); } finally { reportExecutionWatch.Stop(); Log.Information("RenderReport : [{@outputFilename}] Finish generating report in {@time} seconds", reportRequest.outputFilename, reportExecutionWatch.ElapsedMilliseconds / 1000.0); } return ValidatedResponse<string>.Success(fileNameAndPath); }