0
votes

I've been trying to convert a SSRS Report to PDF and save to my local drive using the Reporting Web Services. Though I'm able to generate the corresponding pdf file but the contents of the file are missing. I've checked that the report I'm trying to convert is not an empty one. Only the header section is present there within the generated pdf files. Below is the code I'm using:

protected void GeneratePDFFromReport(object sender, EventArgs e)
    {
        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 = new System.Net.NetworkCredential("username", "password", "domain");
        rsExec.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
        //rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;

        rs.Url = "http://servername/reportserver/reportservice2005.asmx";
        rsExec.Url = "http://servername/reportserver/reportexecution2005.asmx";

        string historyID = null;
        string deviceInfo = null;
        string format = "PDF";
        Byte[] results;
        string encoding = String.Empty;
        string mimeType = "application/pdf";
        string extension = String.Empty;
        RE2005.Warning[] warnings = null;
        string[] streamIDs = null;

        // Path of the Report - XLS, PDF etc.
        string fileName = @"C:\Report\MemberReport.pdf";
        // Name of the report - Please note this is not the RDL file.
        string _reportName = @"/ReportFolder/ReportName";
        string _historyID = null;
        bool _forRendering = false;
        RS2005.ParameterValue[] _values = null;
        RS2005.DataSourceCredentials[] _credentials = null;
        RS2005.ReportParameter[] _parameters = null;

        try
        {
            _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
            RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);

            results = rsExec.Render(format, deviceInfo,
                      out extension, out encoding,
                      out mimeType, out warnings, out streamIDs);

            try
            {
                FileStream stream = File.Create(fileName, results.Length);
                stream.Write(results, 0, results.Length);
                stream.Close();
            }
            catch { }

            results = null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Any help would highly be appreciated. Thanks.

1

1 Answers

0
votes

Assuming that SSRS is working OK using browser, please modify your posted code as shown below:

1) Device info string, please set it as follows:

string deviceInfo =  @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; //Initial value was null

2) Create Header instance before using web call LoadReport:

ExecutionHeader execHeader = new ExecutionHeader();
RE2005.ExecutionHeaderValue = execHeader;