標籤:
一、 建立一個winform應用程式WindowsFormsApplication1
二、 添加web引用 。
報表格服務:http://dbpdhkcax05:80/webservice/ReportService2005.asmx
報表執行服務:http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx
右擊“引用”-> 加入服務參考->輸入URL地址點“前往”載入服務後點“進階”-服務引用設定->點“添加web引用”->在此畫面將2個服務都加入項目。
三、 web服務引用示。(web服務引用的節點一開始沒有,在添加web服務引用後自動產生).
四、 建一form用於輸入參數。
五、 點OK產生報表(VS2008)
1.插入命名空間引用
1 using WindowsFormsApplication1.dbpdhkcax05_rs;2 using WindowsFormsApplication1.dbpdhkcax05_rsexec;
View Code
2.Click OK 代碼
1 dbpdhkcax05_rs.ReportingService2005 rs2005 = new ReportingService2005(); 2 dbpdhkcax05_rsexec.ReportExecutionService rsExec = new ReportExecutionService(); 3 4 rs2005.Credentials = System.Net.CredentialCache.DefaultCredentials; 5 rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials; 6 rsExec.Timeout = -1; 7 8 rs2005.Url = "http://dbpdhkcax05:80/webservice/ReportService2005.asmx?WSDL"; 9 rsExec.Url = "http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx?WSDL";10 11 12 string reportPath = "/Operation/PortalReports/Reliability Details";13 string fileName = @"C:\\testRel.xls";14 15 string format = "EXCEL";16 string historyID = null;17 string devInfo = null;18 bool _forRendering = false;19 20 dbpdhkcax05_rs.ParameterValue[] _values = null;21 dbpdhkcax05_rs.ReportParameter[] _parm = null;22 dbpdhkcax05_rs.DataSourceCredentials[] _cred = null;23 24 _parm = rs2005.GetReportParameters(reportPath, historyID,_forRendering, _values, _cred);25 26 dbpdhkcax05_rsexec.ExecutionInfo execinfo = rsExec.LoadReport(reportPath, historyID);27 28 dbpdhkcax05_rsexec.ParameterValue[] parameters = new WindowsFormsApplication1.dbpdhkcax05_rsexec.ParameterValue[3];29 // Prepare report parameter.30 //ParameterValue[] parameters = new ParameterValue[3];31 parameters[0] = new dbpdhkcax05_rsexec.ParameterValue();32 parameters[0].Name = "StartDate";33 parameters[0].Value = txtFromDate.Text;34 parameters[1] = new dbpdhkcax05_rsexec.ParameterValue();35 parameters[1].Name = "EndDate";36 parameters[1].Value = txtToDate.Text; 37 parameters[2] = new dbpdhkcax05_rsexec.ParameterValue();38 parameters[2].Name = "Company";39 parameters[2].Value = txtCompanyId.Text;40 41 rsExec.SetExecutionParameters(parameters, "en-us");42 Byte[] results;43 string encoding = String.Empty;44 string mimeType = String.Empty;45 string extension = String.Empty;46 string[] streamIDs = null;47 dbpdhkcax05_rsexec.Warning[] warning = null;48 results = rsExec.Render(format, devInfo, out extension, out mimeType, out encoding, out warning, out streamIDs);49 using (FileStream stream = File.OpenWrite(fileName))50 {51 stream.Write(results, 0, results.Length);52 53 }
View Code
用C#訪問SSRS自動匯出SSRS報表