Report Generation in PDF Using SSRS2005

/*The code below explains how to render the report in PDF format programmatically, using C#.
*/

private void createPDF(string reportPdfName)
{
try
{
ReportService2005.ReportingService2005 rs = new ReportService2005.ReportingService2005();
ReportExecution2005.ReportExecutionService rsexe = new ReportExecution2005.ReportExecutionService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsexe.Credentials = System.Net.CredentialCache.DefaultCredentials;

rs.Url = @"http://dotnet2005/ReportServer/ReportService2005.asmx";
rsexe.Url = @"http://dotnet2005/ReportServer/ReportExecution2005.asmx";

//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;

string fileName = @"C:\Artbeat\samplereport.pdf";

//define variables needed for GetParameters() method
//get the report name

//string _reportname = ConfigurationManager.AppSettings["SalesYearlyMainview"].ToString();
string _reportname=reportPdfName;
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 = rsexe.LoadReport(_reportname, historyID);

//Get the no. of parameters in the report.
_parameters = rs.GetReportParameters(_reportname, _historyID, _forRendering, _values, _credentials);
int totalParams = _parameters.Length;


ReportExecution2005.ParameterValue[] parameters = null;

//prepare report parameters
ReportParameterInfoCollection paramCollection = rvResourceUtilReport.ServerReport.GetParameters();
parameters = new ReportExecution2005.ParameterValue[paramCollection.Count];
//forloop to fill the parameter array from the paramCollection
int paramaIndex = 0;
foreach (ReportParameterInfo RepParamInfo in paramCollection)
{
parameters[paramaIndex] = new ReportExecution2005.ParameterValue();
parameters[paramaIndex].Name = RepParamInfo.Name;
parameters[paramaIndex].Value = RepParamInfo.Values[0];
paramaIndex++;
}

rsexe.SetExecutionParameters(parameters, "en-us");
bytPDF = rsexe.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);

using (FileStream stream = File.Create(fileName))
{
stream.Write(bytPDF, 0, bytPDF.Length);
stream.Close();
}


}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.Read();
}
}