Using the program to run the reporting service automatically generates files that can be processed using the Reportexecutionservice.render method.
1. Connect to the Reporting Service server, generate the string HTTP//server address/reportserver/reportexecution2005.asmx, we have this test address of http://192.168.7.191/ Reportserver/reportexecution2005.asmx
2. Add a Web reference in VS to fill in the above server address and add the reference.
3. Add code
4. Using System;
5. Using System.Collections.Generic;
6. Using System.Linq;
7. Using System.Web;
8. Using SYSTEM.WEB.MVC;
9. Using Ssrsgenerate.webreference;
10.
11. Using System.IO;
12.
13. Namespace Ssrsgenerate.controllers
14. {
15. public class Homecontroller:controller
16. {
17. //
18. get:/home/
19.
20. Public ActionResult Index ()
21. {
22. Reportexecutionservicers = new Reportexecutionservice ();
23. Rs. Credentials = System.Net.CredentialCache.DefaultCredentials;
24. Rs. URL = "Http://192.168.7.191/reportserver/reportexecution2005.asmx";
25.
26. Renderarguments
27. Byte[]result = null;
28. Stringreportpath = "/ppo/knitppo_compare/ppo_compare_bulk";
29. StringFormat = "MHTML";//You can also export PDFs
30. Stringhistoryid = null;
31. Stringdevinfo = @ "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
32.
33. Prepare report parameter.
34. Parametervalue[]parameters = new Parametervalue[3];
35. Parameters[0] = new ParameterValue ();
36. Parameters[0]. Name = "EmpID";
37. Parameters[0]. Value = "288";
38. PARAMETERS[1] = new ParameterValue ();
39. PARAMETERS[1]. Name = "Reportmonth";
40. PARAMETERS[1]. Value = "6"; June
41. PARAMETERS[2] = new ParameterValue ();
42. PARAMETERS[2]. Name = "Reportyear";
43. PARAMETERS[2]. Value = "2004";
44.
45. Datasourcecredentials[]credentials = null;
46. Stringshowhidetoggle = null;
47. stringencoding;
48. Stringmimetype;
49. Stringextension;
50. Warning[]warnings = null;
51. Parametervalue[]reporthistoryparameters = null;
52. String[]streamids = null;
54. Executioninfoexecinfo = new Executioninfo ();
55. Executionheaderexecheader = new Executionheader ();
56.
57. Rs. Executionheadervalue =execheader;
58.
59. Execinfo = Rs. Loadreport (Reportpath,historyid);
60.
61. Rs. Setexecutionparameters (Parameters, "en-us");
62. Stringsessionid = Rs. Executionheadervalue.executionid;
63.
64. Console.WriteLine ("SessionID: {0}", Rs. Executionheadervalue.executionid);
65.
67. Try
68. {
69. result = Rs. Render (Format,devinfo, out-extension, out-encoding, out-mimeType, out warnings,outstreamids);
70.
71. Execinfo =rs. Getexecutioninfo ();
73. Console.WriteLine ("Execution date and time: {0}", execinfo.executiondatetime);
76. }
77. catch (SoapException E)
78. {
79. Console.WriteLine (E.detail.outerxml);
80. }
81. Writethe contents of the report to an MHTML file.
82. Try
83. {
84. Filestreamstream = File.create ("report.mht", result. Length);
85. Console.WriteLine ("File created.");
86. Stream. Write (result, 0, result. Length);
87. Console.WriteLine ("Result written to the file.");
88. Stream. Close ();
89. }
90. catch (Exception e)
91. {
92. Console.WriteLine (E.message);
93. }
97. Returnview ();
98. }
99.
100. }
101. }
102.
SSRS Generate reports