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 }); }
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 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 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); }