加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Using two WebServices exposed by SSRS to create PDF report f

发布时间:2020-12-17 02:38:08 所属栏目:安全 来源:网络整理
导读: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

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.

?

  1. static?private?void?CreatePDFReports()
  2. {
  3. //create?proxy?to?the?webservice
  4. ReportService2005.ReportingService2005?rs2005?=?new?ReportService2005.ReportingService2005();
  5. ReportExecution2005.ReportExecutionService?re2005?=?new?ReportExecution2005.ReportExecutionService();
  6. try
  7. {
  8. //authenticate?to?the?web?service?using?windows?credentials
  9. rs2005.Credentials?=?System.Net.CredentialCache.DefaultCredentials;
  10. re2005.Credentials?=?System.Net.CredentialCache.DefaultCredentials;
  11. rs2005.Url?=?ConfigurationSettings.AppSettings["ReportService2005.ReportService2005"];
  12. re2005.Url?=?ConfigurationSettings.AppSettings["ReportExecution2005.ReportExecution2005"];
  13. //prepare?render?arguments
  14. string?historyID?=?null;
  15. string?deviceinfo?=?null;
  16. string?format?=?"PDF";
  17. byte[]?bytPDF;
  18. string?encoding?=?string.Empty;
  19. string?mimeType?=?string.Empty;
  20. string?extension?=?string.Empty;
  21. ReportExecution2005.Warning[]?warnings?=?null;
  22. string[]?streamIDs?=?null;
  23. //define?variables?needed?for?GetParameters()?method
  24. //get?the?report?name
  25. string?_reportname?=?ConfigurationSettings.AppSettings["reportName"];
  26. string?_historyID?=?null;
  27. bool?_forRendering?=?false;
  28. ReportService2005.ParameterValue[]?_values?=?null;
  29. ReportService2005.DataSourceCredentials[]?_credentials?=?null;
  30. ReportService2005.ReportParameter[]?_parameters?=?null;
  31. //load?the?selected?report.
  32. ReportExecution2005.ExecutionInfo?ei?=?re2005.LoadReport(_reportname,?historyID);
  33. //Get?the?no.?of?parameters?in?the?report.
  34. _parameters?=?rs2005.GetReportParameters(_reportname,?_historyID,?_forRendering,?_values,?_credentials);
  35. int?totalParams?=?_parameters.Length;
  36. ReportExecution2005.ParameterValue[]?parameters?=?null;
  37. //prepare?report?parameters
  38. parameters?=?new?ReportExecution2005.ParameterValue[totalParams];
  39. foreach?(ReportService2005.ReportParameter?rp?in?_parameters)
  40. {
  41. switch?(rp.Name)
  42. {
  43. case?"param1_name":
  44. {
  45. parameters[_parameters.Length?-?totalParams]?=?new?scheduleReports.ReportExecution2005.ParameterValue();
  46. parameters[_parameters.Length?-?totalParams].Name?=?rp.Name;
  47. parameters[_parameters.Length?-?totalParams].Value?=?1;
  48. }
  49. break;
  50. case?"param2_name":
  51. {
  52. parameters[_parameters.Length?-?totalParams]?=?new?scheduleReports.ReportExecution2005.ParameterValue();
  53. parameters[_parameters.Length?-?totalParams].Name?=?rp.Name;
  54. parameters[_parameters.Length?-?totalParams].Value?=?100;
  55. }
  56. break;
  57. }
  58. totalParams--;
  59. }
  60. re2005.SetExecutionParameters(parameters,?"en-us");
  61. bytPDF?=?re2005.Render(format,?deviceinfo,?out?extension,?out?encoding,?out?mimeType,?out?warnings,?out?streamIDs);
  62. FileStream?fs?=?new?FileStream("report.pdf",?FileMode.OpenOrCreate,?FileAccess.Write);
  63. fs.Write(bytPDF,?0,?bytPDF.Length);
  64. fs.Close();
  65. }
  66. catch?(Exception?ex)
  67. {
  68. Console.WriteLine(ex.Message);
  69. Console.Read();
  70. }
  71. }?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读