none
Unable to Render SSRS Report in Console Application C# RRS feed

  • Question

  • Hello ,

    My SQL Server version is Microsoft SQL Server 2012 - 11.0.2218.0

    I created a SSRS report and deployed to the ssrs report server. I am trying to render it in console application using c#. I followed these approaches

    https://msdn.microsoft.com/en-us/library/aa258532

    and 

    https://msdn.microsoft.com/en-in/library/reportexecution2005.reportexecutionservice.render.aspx

    I have added below Web  services to the project ie : 

    http://myserver/ReportServer/ReportService2010.asmx

    http://myserver/ReportServer/reportexecution2005.asmx

    And in program.cs I have written the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Web.Services.Protocols;
    using RenderApp.RS2010;
    using RenderApp.RE2005;
    
    
    
    namespace RenderApp
    {
        class Program
        {
            static void Main(string[] args)
            {
    
    
                ReportingService2005 rs = new ReportingService2005();
                rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
                byte[] result = null;
                string reportPath = "/TestRender/test";
                string format = "MHTML";
                string historyID = null;
                string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
    
                DataSourceCredentials[] credentials = null;
                string showHideToggle = null;
                string encoding;
                string mimeType;
                Warning[] warnings = null;
                ParameterValue[] reportHistoryParameters = null;
                string[] streamIDs = null;
                ExecutionHeader sh = new ExecutionHeader();
                string str = sh.ExecutionID;
                //rs.Render(reportPath, format, historyID, devInfo, null, credentials,
                //showHideToggle, out encoding, out mimeType, out reportHistoryParameters, out warnings,
                //out streamIDs);
    
    
                ExecutionInfo execInfo = new ExecutionInfo();
                ExecutionHeader execHeader = new ExecutionHeader();
    
                rs.ExecutionHeaderValue = execHeader;
    
                execInfo = rs.LoadReport(reportPath, historyID);
    
                rs.SetExecutionParameters(parameters, "en-us");
                String SessionId = rs.ExecutionHeaderValue.ExecutionID;
                try
                {
                    result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
    
                    execInfo = rs.GetExecutionInfo();
    
                    Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
    
    
                }
                catch (SoapException e)
                {
                    Console.WriteLine(e.Detail.OuterXml);
                }
                // Write the contents of the report to an MHTML file.
                try
                {
                    FileStream stream = File.Create("report.mht", result.Length);
                    Console.WriteLine("File created.");
                    stream.Write(result, 0, result.Length);
                    Console.WriteLine("Result written to the file.");
                    stream.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
    
            }
        }
    }

    But, the above code is not able to find the proper methods or classes. See below pic for reference.


    How Can I solve this issue and render  succesfully. Am I missing something ?

    Thanks in advance.




    Saturday, February 27, 2016 4:59 PM

All replies

  • Hi Chakradhar,

    To render a report server report in console application to a specified format, please add those two web services to the project:

    Reporting Service 2005 : http://[SERVER]/reportserver/reportservice2005.asmx
    Report Execution Service : http://[SERVER]/reportserver/reportexecution2005.asmx

    Then write the C# code mentioned in this article to execute and save the report:
    How To: Execute and Save SSRS Report using C#

    If you have any question, please feel free to ask.

    Best regards,
    Qiuyun Yu


    Qiuyun Yu
    TechNet Community Support


    Monday, February 29, 2016 6:13 AM
    Moderator
  • Hello Qiuyun ,

    Yes, I tried with that approach too. But , No luck.

    I am not able to initiate the 

    ReportExecutionService();

    Even After including these webservices.

    Reporting Service 2005 : http://[SERVER]/reportserver/reportservice2005.asmx
    Report Execution Service : http://[SERVER]/reportserver/reportexecution2005.asmx

    I am not sure what I am missing !

    Thanks,

    Chakra

    Monday, February 29, 2016 12:53 PM
  • ReportService2005 endpoint is used for managing objects on a report server that is configured for native mode. Are you running SHrePoint mode?

    https://msdn.microsoft.com/en-us/library/ms155398.aspx?f=255&MSPPError=-2147217396


    Work hard, play harder!

    Wednesday, March 2, 2016 9:47 AM