SSRS Report generation in C#

I was googling through how to call existed SSRS Reports hosted in Report manager. Many of the Links contains we can call it through Report Viewer control.

But there is some other work around using the web references.

  1. ReportExecution2005 Services
  2. ReportServer2005 Services

In the Application from where you want to call SSRS Reports add the Web references of above two web references in to the Project

Creating instances of the Web references

     RS2005.ReportingService2005 rs;
     RE2005.ReportExecutionService rsExec;

    
// Create a new proxy to the web service
     rs = new RS2005.ReportingService2005();

     rsExec = new RE2005.ReportExecutionService(); 

 
    // Authenticate to the Web service using Windows credentials
     rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
     rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
 
     rs.Url = "http://reportserverprod/reportserver/reportservice2005.asmx";
     rsExec.Url = "http://reportserverprod/reportserver/reportexecution2005.asmx";
 
     //Set the format to which you want to export
 

    string
historyID = null;
    string deviceInfo = null;
    string format = "EXCEL";
    Byte[] results;
    string encoding = String.Empty;
    string mimeType = String.Empty;
    string extension = String.Empty;
    RE2005.Warning[] warnings = null;
    string[] streamIDs = null;
 
    
// Path of the Report - XLS, PDF etc.
    string fileName = @"c:\samplereport.xls"; //Give Local path name where you want to save

    // Name of the report - Please note this is not the RDL file.
    string _reportName = @"/Report_EligLoad/Eligibility Load Detail"; //path of the Report where its been hosted
    string _historyID = null;
    bool _forRendering = false;
    RS2005.ParameterValue[] _values = null;
    RS2005.DataSourceCredentials[] _credentials = null;
    RS2005.ReportParameter[] _parameters = null;

//Set the parameters

rsExec.SetExecutionParameters(parameters, "en-us");

//Save it into the location

 using (FileStream stream = File.OpenWrite(fileName))
{
      stream.Write(results, 0, results.Length);
}