private void Render(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, List <KeyValuePair <string, string> > ReportParameters, string ParameterLanguage, string RenderFormat, string RenderPath) { ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[ReportParameters.Count()]; int index = 0; string paramString = string.Empty; foreach (var item in ReportParameters) { parameters[index] = new ReportExecution2005.ParameterValue(); parameters[index].Name = item.Key; parameters[index].Value = item.Value; index++; paramString = paramString + item.Key + "=" + item.Value + "&"; } string cachedKey = ReportServerPath + @"/" + ReportFolder + @"/" + ReportName + @"?" + paramString; if (cachedFiles.ContainsKey(cachedKey)) //load report from cache { RenderPath = cachedFiles[cachedKey]; if (!string.IsNullOrEmpty(RenderPath) && File.Exists(RenderPath)) { return; } } byte[] bytes; GetReportData(ReportServerPath, UserName, UserPassword, ReportMode, ReportHttpClientCredentialType, ReportFolder, ReportName, parameters, ParameterLanguage, RenderFormat, out bytes); if (bytes != null && !string.IsNullOrEmpty(RenderPath)) { try { string folderName = RenderPath.Substring(0, RenderPath.LastIndexOf('\\') + 1); string fileName = CleanFileName(RenderPath.Substring(RenderPath.LastIndexOf('\\') + 1)); using (FileStream fs = File.Create(folderName + fileName)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); } cachedFiles[cachedKey] = RenderPath; } catch (IOException ex) { LogMessage("Not able to create file " + RenderPath + ". Error: " + ex.Message); throw; } } }
private void Render(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, List <KeyValuePair <string, string> > ReportParameters, string ParameterLanguage, out XElement xDocument) { xDocument = null; ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[ReportParameters.Count()]; int index = 0; string paramString = string.Empty; foreach (var item in ReportParameters) { parameters[index] = new ReportExecution2005.ParameterValue(); parameters[index].Name = item.Key; parameters[index].Value = item.Value; index++; paramString = paramString + item.Key + "=" + item.Value + "&"; } string cachedKey = ReportServerPath.TrimEnd('/') + @"/" + ReportFolder.TrimStart('/').TrimEnd('/') + @"/" + ReportName + @"?" + paramString; if (cachedReports.ContainsKey(cachedKey)) //load report from cache { xDocument = cachedReports[cachedKey]; return; } byte[] bytes; GetReportData(ReportServerPath, UserName, UserPassword, ReportMode, ReportHttpClientCredentialType, ReportFolder, ReportName, parameters, ParameterLanguage, "XML", out bytes); if (bytes != null) { using (MemoryStream ms = new MemoryStream(bytes)) { XNamespace test = XNamespace.Get(ReportName); XNamespace xsi = XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance"); XmlReader reader = XmlReader.Create(ms); xDocument = StripNS(XElement.Load(reader, LoadOptions.None)); xDocument.Attributes().Remove(); xDocument = new XElement("Report" , new XAttribute(XNamespace.Xmlns + "test", ReportName) //blank.NamespaceName , new XAttribute(XNamespace.Xmlns + "xsi", xsi) , xDocument.Nodes()); } cachedReports[cachedKey] = xDocument; } }
protected static string GetReport(string reportpath, string format, List <RC_ParamReports> Param, string NameFile) { ReportExecutionService re2005 = new ReportExecutionService(); re2005.Credentials = CredentialCache.DefaultCredentials; // Render arguments byte[] result = null; string historyID = null; string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; // Prepare report parameter ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[Param.Count]; for (int i = 0; i < Param.Count; i++) { parameters[i] = new ReportExecution2005.ParameterValue(); parameters[i].Name = Param[i].Name; parameters[i].Value = GetParamValue(Param[i].Type, Param[i].ValueFix, Param[i].ValueExpression, Param[i].Format); Console.WriteLine("Param[i].Name = {0}; Param[i].ValueExpression = {1}; Param[i].ValueCatalog = {2}; Param[i].ValueFix = {3}", Param[i].Name, Param[i].ValueExpression, Param[i].ValueCatalog, Param[i].ValueFix); Console.WriteLine("parameters[i].Name = {0}; parameters[i].Value = {1}", parameters[i].Name, parameters[i].Value); } //Блок херни ReportExecution2005.DataSourceCredentials[] credentials = null; string showHideToggle = null; string encoding; string mimeType; string extension = ""; ReportExecution2005.Warning[] warnings = null; ReportExecution2005.ParameterValue[] reportHistoryParameters = null; string[] streamIDs = null; // ExecutionInfo execInfo = new ExecutionInfo(); ExecutionHeader execHeader = new ExecutionHeader(); try {// re2005.ExecutionHeaderValue = execHeader; execInfo = re2005.LoadReport(reportpath, historyID); re2005.SetExecutionParameters(parameters, "ru-RU"); String SessionId = re2005.ExecutionHeaderValue.ExecutionID; ///Console.WriteLine("SessionID: {0}", re2005.ExecutionHeaderValue.ExecutionID); result = re2005.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); ///Console.WriteLine("format = {0}; devInfo = {1}; extension = {2}; encoding = {3}; mimeType = {4}; warnings = {5}; streamIDs = {6}", format, devInfo, extension, encoding, mimeType, warnings, streamIDs); } catch (SoapException e) { Console.WriteLine(e.Detail.OuterXml); } catch (Exception e) { Console.WriteLine(e.Message); } ///finally { Console.WriteLine(e.Message); } // Write the contents of the report to an MHTML file. try { using (FileStream stream = System.IO.File.Create(NameFile, result.Length)) { ///Console.WriteLine("File created."); stream.Write(result, 0, result.Length); Console.WriteLine("Result written to the file {0}.", NameFile); // stream.Close(); } } catch (Exception e) { Console.WriteLine("ОШИБКА " + e.Message); } return(NameFile); }
public Byte[] GetByte(string ReportServerUrl, string ReportUserName, string ReportPassword, string ReportDomain, string ReportPath, string ReportName, List <ReportParameter> paramter, ExportType exportType) { // Prepare Render arguments string historyID = null; string deviceInfo = null; string format = exportType.ToString(); Byte[] results; string encoding = String.Empty; string mimeType = String.Empty; string extension = String.Empty; ReportExecution2005.Warning[] warnings = null; string[] streamIDs = null; ReportExecution2005.ParameterValue[] rptParameters = null; try { ReportExecution2005.ReportExecutionService myReport = new ReportExecution2005.ReportExecutionService(); myReport.Url = ReportServerUrl; if (ReportDomain != string.Empty && ReportDomain.Length > 0) { myReport.Credentials = new System.Net.NetworkCredential(ReportUserName, ReportPassword, ReportDomain); } else { myReport.Credentials = new System.Net.NetworkCredential(ReportUserName, ReportPassword); } ReportExecution2005.ExecutionInfo ei; if (ReportPath != null && ReportPath.Length > 0) { ei = myReport.LoadReport("/" + ReportPath + "/" + ReportName, historyID); } else { if (ReportName != null && ReportName.Length > 0) { ei = myReport.LoadReport("/" + ReportName, historyID); } else { return(new Byte[0]); } } /* This code for set credentials on runtime * require [using SCG.eAccounting.Report.ReportExecution2005;] * if (ei.CredentialsRequired) * { * List<DataSourceCredentials> credentials = new List<DataSourceCredentials>(); * foreach (DataSourcePrompt dsp in ei.DataSourcePrompts) * { * DataSourceCredentials cred = new DataSourceCredentials(); * cred.DataSourceName = dsp.Name; * cred.UserName = [Database Username]; * cred.Password = [Database Password]; * credentials.Add(cred); * } * * Console.WriteLine("Setting data source credentials..."); * ei = myReport.SetExecutionCredentials(credentials.ToArray()); * } */ if (paramter != null && paramter.Count > 0) { rptParameters = new ReportExecution2005.ParameterValue[paramter.Count]; for (int i = 0; i < paramter.Count; i++) { rptParameters[i] = new ReportExecution2005.ParameterValue(); rptParameters[i].Name = paramter[i].ParamterName; rptParameters[i].Value = paramter[i].ParamterValue; } } deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>"; //render the PDF myReport.SetExecutionParameters(rptParameters, "th-TH"); results = myReport.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); } catch (Exception e) { throw e; } return(results); }
public Public.ImageStream Render(Public.WebService.WebServiceHostConfiguration webServiceHostConfiguration, String reportName, Dictionary <String, String> forReportParameters, String format, Dictionary <String, String> extendedProperties) { Public.ImageStream imageStream = new Public.ImageStream(); Boolean deviceInfoHumanReadablePdf = ((extendedProperties.ContainsKey("DeviceInfoHumanReadablePdf")) ? Convert.ToBoolean(extendedProperties["DeviceInfoHumanReadablePdf"]) : false); #region Initialization // ENABLE IMPERSONATION FROM THREAD IDENTITY // AppDomain.CurrentDomain.SetPrincipalPolicy (System.Security.Principal.PrincipalPolicy.WindowsPrincipal); // System.Security.Principal.WindowsImpersonationContext impersonationContext = null; // impersonationContext = ((System.Security.Principal.WindowsIdentity)System.Threading.Thread.CurrentPrincipal.Identity).Impersonate (); // CONFIGURE REPORTING SERVICE HOST reportExecutionClient = new ReportExecution2005.ReportExecutionServiceSoapClient(webServiceHostConfiguration.BindingConfiguration.Binding, webServiceHostConfiguration.EndpointAddress); reportExecutionClient.ClientCredentials.Windows.AllowedImpersonationLevel = webServiceHostConfiguration.ClientCredentials.WindowsImpersonationLevel; reportExecutionClient.ClientCredentials.Windows.ClientCredential = webServiceHostConfiguration.ClientCredentials.Credentials; #region Old Connection Information //Server.Public.WebService.WebServiceHostConfiguration serviceHostReporting = new Server.Public.WebService.WebServiceHostConfiguration ( // "qstestmcm001", 80, "ReportServer", "ReportExecution2005.asmx" // ); //serviceHostReporting.ClientCredentials.WindowsImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; //serviceHostReporting.BindingConfiguration = new Server.Public.WebService.BindingConfiguration ("BasicHttpBinding", Server.Public.WebService.Enumerations.WebServiceBindingType.BasicHttpBinding); //serviceHostReporting.BindingConfiguration.SecurityMode = System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly; //serviceHostReporting.BindingConfiguration.TransportCredentialType = System.ServiceModel.HttpClientCredentialType.Ntlm; //serviceHostReporting.BindingConfiguration.MessageCredentialType = System.ServiceModel.MessageCredentialType.UserName; //System.ServiceModel.BasicHttpBinding binding = (System.ServiceModel.BasicHttpBinding)serviceHostReporting.BindingConfiguration.Binding; ////binding.AllowCookies = true; //reportExecutionClient = new ReportExecution2005.ReportExecutionServiceSoapClient (binding, serviceHostReporting.EndpointAddress); //reportExecutionClient.ClientCredentials.Windows.AllowedImpersonationLevel = serviceHostReporting.ClientCredentials.WindowsImpersonationLevel; //reportExecutionClient.ClientCredentials.Windows.ClientCredential = serviceHostReporting.ClientCredentials.Credentials; #endregion // OPEN UP THE MAX OBJECTS IN GRAPH TO MAXIMUM foreach (System.ServiceModel.Description.OperationDescription currentOperation in reportExecutionClient.Endpoint.Contract.Operations) { System.ServiceModel.Description.DataContractSerializerOperationBehavior dataContractSerializer = (System.ServiceModel.Description.DataContractSerializerOperationBehavior) currentOperation.Behaviors.Find <System.ServiceModel.Description.DataContractSerializerOperationBehavior> (); if (dataContractSerializer != null) { dataContractSerializer.MaxItemsInObjectGraph = Int32.MaxValue; } } #endregion #region Render Report SqlServer.ReportExecution2005.ExecutionHeader executionHeader; SqlServer.ReportExecution2005.ServerInfoHeader serverInfoHeader; SqlServer.ReportExecution2005.ExecutionInfo executionInfo; SqlServer.ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[forReportParameters.Count]; Byte[] renderedReport; String reportExtension; String reportMimeType; String reportEncoding; SqlServer.ReportExecution2005.Warning[] reportWarnings; String[] reportStreamIds; executionHeader = reportExecutionClient.LoadReport(null, reportName, null, out serverInfoHeader, out executionInfo); // COPY PARAMETERS Int32 currentParameterIndex = 0; foreach (String currentParameterName in forReportParameters.Keys) { parameters[currentParameterIndex] = new ReportExecution2005.ParameterValue(); parameters[currentParameterIndex].Label = currentParameterName; parameters[currentParameterIndex].Name = currentParameterName; parameters[currentParameterIndex].Value = forReportParameters[currentParameterName]; currentParameterIndex = currentParameterIndex + 1; } reportExecutionClient.SetExecutionParameters(executionHeader, null, parameters, "en-us", out executionInfo); // SET UP DEVICE INFORMATION String deviceInfo = String.Empty; switch (format.ToLower()) { case "pdf": deviceInfo = (deviceInfoHumanReadablePdf) ? @"<DeviceInfo><HumanReadablePDF>True</HumanReadablePDF></DeviceInfo>" : String.Empty; break; } serverInfoHeader = reportExecutionClient.Render(executionHeader, null, format, ((!String.IsNullOrEmpty(deviceInfo)) ? deviceInfo : null), out renderedReport, out reportExtension, out reportMimeType, out reportEncoding, out reportWarnings, out reportStreamIds); imageStream.Image = new System.IO.MemoryStream(renderedReport); imageStream.Name = reportName; imageStream.Extension = reportExtension; imageStream.MimeType = reportMimeType; #endregion return(imageStream); }
private void Render(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, List<KeyValuePair<string, string>> ReportParameters, string ParameterLanguage, string RenderFormat, string RenderPath) { ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[ReportParameters.Count()]; int index = 0; string paramString = string.Empty; foreach (var item in ReportParameters) { parameters[index] = new ReportExecution2005.ParameterValue(); parameters[index].Name = item.Key; parameters[index].Value = item.Value; index++; paramString = paramString + item.Key + "=" + item.Value + "&"; } string cachedKey = ReportServerPath + @"/" + ReportFolder + @"/" + ReportName + @"?" + paramString; if (cachedFiles.ContainsKey(cachedKey)) //load report from cache { RenderPath = cachedFiles[cachedKey]; if (!string.IsNullOrEmpty(RenderPath) && File.Exists(RenderPath)) { return; } } byte[] bytes; GetReportData(ReportServerPath, UserName, UserPassword, ReportMode, ReportHttpClientCredentialType, ReportFolder, ReportName, parameters, ParameterLanguage, RenderFormat, out bytes); if (bytes != null && !string.IsNullOrEmpty(RenderPath)) { try { string folderName = RenderPath.Substring(0, RenderPath.LastIndexOf('\\') + 1); string fileName = CleanFileName(RenderPath.Substring(RenderPath.LastIndexOf('\\') + 1)); using (FileStream fs = File.Create(folderName + fileName)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); } cachedFiles[cachedKey] = RenderPath; } catch (IOException ex) { LogMessage("Not able to create file " + RenderPath + ". Error: " + ex.Message); throw; } } }
private void Render(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, List<KeyValuePair<string, string>> ReportParameters, string ParameterLanguage, out XElement xDocument) { xDocument = null; ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[ReportParameters.Count()]; int index = 0; string paramString = string.Empty; foreach (var item in ReportParameters) { parameters[index] = new ReportExecution2005.ParameterValue(); parameters[index].Name = item.Key; parameters[index].Value = item.Value; index++; paramString = paramString + item.Key + "=" + item.Value + "&"; } string cachedKey = ReportServerPath.TrimEnd('/') + @"/" + ReportFolder.TrimStart('/').TrimEnd('/') + @"/" + ReportName + @"?" + paramString; if (cachedReports.ContainsKey(cachedKey)) //load report from cache { xDocument = cachedReports[cachedKey]; return; } byte[] bytes; GetReportData(ReportServerPath, UserName, UserPassword, ReportMode, ReportHttpClientCredentialType, ReportFolder, ReportName, parameters, ParameterLanguage, "XML", out bytes); if (bytes != null) { using (MemoryStream ms = new MemoryStream(bytes)) { XNamespace test = XNamespace.Get(ReportName); XNamespace xsi = XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance"); XmlReader reader = XmlReader.Create(ms); xDocument = StripNS(XElement.Load(reader, LoadOptions.None)); xDocument.Attributes().Remove(); xDocument = new XElement("Report" , new XAttribute(XNamespace.Xmlns + "test", ReportName) //blank.NamespaceName , new XAttribute(XNamespace.Xmlns + "xsi", xsi) , xDocument.Nodes()); } cachedReports[cachedKey] = xDocument; } }
private byte[] RenderReport(ReportsContainer reportsContainer, Report report) { byte[] reportFile = null; string ReportDbFilestreamPathName = string.Empty; if (string.IsNullOrEmpty(reportsContainer.ReportServiceUrl) || string.IsNullOrEmpty(reportsContainer.ReportExecutionUrl)) { throw new Exception("Atributos ReportServicesUrl e ReportExecutionUrl devem ser definidos"); } //Instancia as classes do ReportingService _rsService = new ReportingService2005(); _rsExecution = new ReportExecutionService(); if (reportsContainer.CredentialType == CredentialType.DefaultCredential) { _rsService.Credentials = CredentialCache.DefaultCredentials; _rsExecution.Credentials = CredentialCache.DefaultCredentials; } else if (reportsContainer.CredentialType == CredentialType.NetworkCredential) { _rsService.Credentials = CredentialCache.DefaultNetworkCredentials; _rsExecution.Credentials = CredentialCache.DefaultNetworkCredentials; } else { _credential = new NetworkCredential { UserName = reportsContainer.ReportUserLogin, Password = reportsContainer.ReportUserPassword, Domain = reportsContainer.NetworkDomain }; _rsService.Credentials = _credential; _rsExecution.Credentials = _credential; } //Define a URL do Servidor que vai gerar o relatório _rsService.Url = reportsContainer.ReportServiceUrl; _rsExecution.Url = reportsContainer.ReportExecutionUrl; _reportName = @"/" + report.ReportName; _historyID = null; _forRendering = false; //Carrega a session para o relatorio selecionado ReportExecution2005.ExecutionInfo _executionInfo = _rsExecution.LoadReport(_reportName, _historyID); //Prepara os parametros do relatório. ReportExecution2005.ParameterValue[] reportExecutionParameters = new ReportExecution2005.ParameterValue[report.Parameters.Count]; //lista todos os parametros do objeto Report e carrega nos parametros do relatório int contador = 0; foreach (KeyValuePair<string, object> parametro in report.Parameters) { reportExecutionParameters[contador++] = new ReportExecution2005.ParameterValue { Name = parametro.Key, Value = parametro.Value.ToString() }; } //definindo os valores dos parametros do relatório _rsExecution.SetExecutionParameters(reportExecutionParameters, "en-us"); //o relatorio é armazenado como um array de bytes if (report.ReportFormat == ReportFormat.HTML4) reportFile = _rsExecution.Render("HTML4.0", _deviceInfo, out _extension, out _encoding, out _mimeType, out _warnings, out _streamIDs); else reportFile = _rsExecution.Render(report.ReportFormat.ToString(), _deviceInfo, out _extension, out _encoding, out _mimeType, out _warnings, out _streamIDs); return reportFile; }
private byte[] RenderReport(Report report) { byte[] reportFile = null; string ReportDbFilestreamPathName = string.Empty; _reportName = @"/" + report.ReportName; _historyID = null; _forRendering = false; //busca no reportService os parametros exigidos pelo relatório (caso queira utilizar para alguma verificação) //ReportService2005.ParameterValue[] _parameterValues = null; //ReportService2005.DataSourceCredentials[] _dsCredentials = null; //ReportService2005.ReportParameter[] _reportParameters = null; //_reportParameters = _rsService.GetReportParameters(_reportName, _historyID, _forRendering, _parameterValues, _dsCredentials); //Carrega a session para o relatorio selecionado ReportExecution2005.ExecutionInfo _executionInfo = _rsExecution.LoadReport(_reportName, _historyID); //Prepara os parametros do relatório. ReportExecution2005.ParameterValue[] reportExecutionParameters = new ReportExecution2005.ParameterValue[report.Parameters.Count]; //lista todos os parametros do objeto Report e carrega nos parametros do relatório int contador = 0; foreach (KeyValuePair<string, object> parametro in report.Parameters) { reportExecutionParameters[contador++] = new ReportExecution2005.ParameterValue { Name = parametro.Key, Value = parametro.Value.ToString() }; } //definindo os valores dos parametros do relatório _rsExecution.SetExecutionParameters(reportExecutionParameters, "en-us"); //o relatorio é armazenado como um array de bytes if (report.ReportFormat == ReportFormat.HTML4) reportFile = _rsExecution.Render("HTML4.0", _deviceInfo, out _extension, out _encoding, out _mimeType, out _warnings, out _streamIDs); else reportFile = _rsExecution.Render(report.ReportFormat.ToString(), _deviceInfo, out _extension, out _encoding, out _mimeType, out _warnings, out _streamIDs); return reportFile; }