First, create a new WinForm application WindowsFormsApplication1
Second, add a Web reference.
Reporting Services: Http://dbpdhkcax05:80/webservice/ReportService2005.asmx
Report Execution Service: Http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx
Right-click "Reference", "Add Service Reference," Enter the URL address point, "go to" load the service, point to "advanced"-Service reference settings, click "Add Web Reference" on this screen to add 2 services to the project.
Third, the Web service reference is shown. (The node that the Web service refers to does not start automatically when you add a Web service reference).
Iv. build a form for input parameters.
Five, click OK to generate the report (VS2008)
1. Inserting a namespace reference
1 using windowsformsapplication1.dbpdhkcax05_rs; 2 using Windowsformsapplication1.dbpdhkcax05_rsexec;
View Code
2.Click OK Code
1Dbpdhkcax05_rs. ReportingService2005 rs2005 =NewReportingService2005 ();2Dbpdhkcax05_rsexec. Reportexecutionservice rsexec =NewReportexecutionservice ();3 4rs2005. Credentials =System.Net.CredentialCache.DefaultCredentials;5Rsexec.credentials =System.Net.CredentialCache.DefaultCredentials;6Rsexec.timeout =-1;7 8rs2005. URL ="Http://dbpdhkcax05:80/webservice/ReportService2005.asmx?WSDL";9Rsexec.url ="Http://dbpdhkcax05:80/webservice/ReportExecution2005.asmx?WSDL";Ten One A stringReportpath ="/operation/portalreports/reliability Details"; - stringFileName =@"C:\\testrel.xls"; - the stringFormat ="EXCEL"; - stringHistoryid =NULL; - stringDevInfo =NULL; - BOOL_forrendering =false; + -Dbpdhkcax05_rs. parametervalue[] _values =NULL; +Dbpdhkcax05_rs. reportparameter[] _parm =NULL; ADbpdhkcax05_rs. datasourcecredentials[] _cred =NULL; at -_parm =rs2005. Getreportparameters (Reportpath, historyid,_forrendering, _values, _cred); - -Dbpdhkcax05_rsexec. Executioninfo Execinfo =Rsexec.loadreport (Reportpath, Historyid); - -Dbpdhkcax05_rsexec. parametervalue[] Parameters =NewWindowsformsapplication1.dbpdhkcax05_rsexec. parametervalue[3]; in //Prepare report parameter. - //parametervalue[] Parameters = new Parametervalue[3]; toparameters[0] =Newdbpdhkcax05_rsexec. ParameterValue (); +parameters[0]. Name ="StartDate"; -parameters[0]. Value =Txtfromdate.text; theparameters[1] =Newdbpdhkcax05_rsexec. ParameterValue (); *parameters[1]. Name ="EndDate"; $parameters[1]. Value =Txttodate.text;Panax Notoginsengparameters[2] =Newdbpdhkcax05_rsexec. ParameterValue (); -parameters[2]. Name =" Company"; theparameters[2]. Value =Txtcompanyid.text; + ARsexec.setexecutionparameters (Parameters,"en -US"); the byte[] results; + stringencoding =String.Empty; - stringMimeType =String.Empty; $ stringExtension =String.Empty; $ string[] Streamids =NULL; -Dbpdhkcax05_rsexec. warning[] Warning =NULL; -Results = rsexec.render (format, DevInfo, outExtension outMimeType, outEncoding outWarning outstreamids); the using(FileStream stream =File.openwrite (fileName)) - {WuyiStream. Write (Results,0, results. Length); the -}
View Code
Use C # to access SSRS automatically export SSRS reports