Using two WebServices exposed by SSRS to create PDF report formats programmatically
来源:互联网 发布:C语言cost 编辑:程序博客网 时间:2024/05/20 23:40
I had a requirement to automate the generation of PDF files of SSRS reports.
Figured out a way to use 2 webservices exposed by SQL Server Reporting Services 2005:
a. ReportService2005
b. ReportExecution2005
Implementation:
a. Create SSRS reports and deploy it on the report server.
b. In the windows application add reference to the 2 SSRS webservices: ReportService2005, ReportExecution2005
c. Set default report credentials.
d. Set 2 webservies url
e. Load the SSRS report using ReportExecution2005
f. Get SSRS reportparameters using ReportService2005, to get the total parameters in the report and set the appropriate parameters value to render the report using ReportExecution2005. (confused !!!. Check the code below)
g. Set report parameters using SetExecutionParameters() method of ReportExecution2005.
h. Render the report to get the PDF in byteArray format.
i. Write the pdf byteArray[] to the given pdf file using FileStream Class.
- static private void CreatePDFReports()
- {
- //create proxy to the webservice
- ReportService2005.ReportingService2005 rs2005 = new ReportService2005.ReportingService2005();
- ReportExecution2005.ReportExecutionService re2005 = new ReportExecution2005.ReportExecutionService();
- try
- {
- //authenticate to the web service using windows credentials
- rs2005.Credentials = System.Net.CredentialCache.DefaultCredentials;
- re2005.Credentials = System.Net.CredentialCache.DefaultCredentials;
- rs2005.Url = ConfigurationSettings.AppSettings["ReportService2005.ReportService2005"];
- re2005.Url = ConfigurationSettings.AppSettings["ReportExecution2005.ReportExecution2005"];
- //prepare render arguments
- string historyID = null;
- string deviceinfo = null;
- string format = "PDF";
- byte[] bytPDF;
- string encoding = string.Empty;
- string mimeType = string.Empty;
- string extension = string.Empty;
- ReportExecution2005.Warning[] warnings = null;
- string[] streamIDs = null;
- //define variables needed for GetParameters() method
- //get the report name
- string _reportname = ConfigurationSettings.AppSettings["reportName"];
- string _historyID = null;
- bool _forRendering = false;
- ReportService2005.ParameterValue[] _values = null;
- ReportService2005.DataSourceCredentials[] _credentials = null;
- ReportService2005.ReportParameter[] _parameters = null;
- //load the selected report.
- ReportExecution2005.ExecutionInfo ei = re2005.LoadReport(_reportname, historyID);
- //Get the no. of parameters in the report.
- _parameters = rs2005.GetReportParameters(_reportname, _historyID, _forRendering, _values, _credentials);
- int totalParams = _parameters.Length;
- ReportExecution2005.ParameterValue[] parameters = null;
- //prepare report parameters
- parameters = new ReportExecution2005.ParameterValue[totalParams];
- foreach (ReportService2005.ReportParameter rp in _parameters)
- {
- switch (rp.Name)
- {
- case "param1_name":
- {
- parameters[_parameters.Length - totalParams] = new scheduleReports.ReportExecution2005.ParameterValue();
- parameters[_parameters.Length - totalParams].Name = rp.Name;
- parameters[_parameters.Length - totalParams].Value = 1;
- }
- break;
- case "param2_name":
- {
- parameters[_parameters.Length - totalParams] = new scheduleReports.ReportExecution2005.ParameterValue();
- parameters[_parameters.Length - totalParams].Name = rp.Name;
- parameters[_parameters.Length - totalParams].Value = 100;
- }
- break;
- }
- totalParams--;
- }
- re2005.SetExecutionParameters(parameters, "en-us");
- bytPDF = re2005.Render(format, deviceinfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
- FileStream fs = new FileStream("report.pdf", FileMode.OpenOrCreate, FileAccess.Write);
- fs.Write(bytPDF, 0, bytPDF.Length);
- fs.Close();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- Console.Read();
- }
- }
- Using two WebServices exposed by SSRS to create PDF report formats programmatically
- Highcharts using svg image to create pdf
- Programmatically split an editor area to show two editors side by side
- SSRS: How to Display Checkbox on Report
- To create a sharepoint list by using powershell
- Removing reports / report folder by SSRS (SQL SERVER REPORTING SERVICE)
- How to test VPNaaS using two KVM VMs (by quqi99)
- CRM 2011 Online SSRS report UTC time to local time
- X++ Run report To PDF
- Create document set programmatically
- How to Create an Report Style
- Saving Word 2007 Documents to PDF and XPS Formats
- How To Create an ASP.NET HTTP Handler by Using Visual C# .NET
- Step By Step Guide To Create Physical Standby Database Using RMAN Backup and Restore
- How to create new view by using cleartool command in Clearcase?
- Excel--Create an Excel Pivot Table report using VBA
- Programmatically create and display Notifications
- Using Microsoft Virtual Server 2005 to Create and Configure a Two-Node Microsoft Windows Server 2003 Cluster
- 希望
- sql2005转到sql2000
- 辞职报告
- 数组排序
- 【征集】面试第二问,在友情和公司利益间选择,你最要好的同事违反了公司的制度,而领导不知道, 你该怎么做
- Using two WebServices exposed by SSRS to create PDF report formats programmatically
- Java 编程技术中汉字问题的分析
- CVS使用手册
- LWIP_pbuf.c
- Head First C# 中文版 图文皆译 第二章 page46
- char[],*char, string, cstring有什么区别?
- ASP.NET快捷键
- POSIX无缓冲文件I/O及可变参数小玩
- API串口操作封装类