Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering SSRS in C# console app; where to find SSRS ReportExecutionService?

In a C# console app I’m trying to render an SSRS report on our reporting server, then I’ll stream it out to a PDF file. I’ve found multiple bits of documentation but I’m running into a roadblock… how do I add a reference to the Report Execution Service?

I was able to follow the first step in the code samples… I add a Service Reference / clicked Add Web Reference, typed in http://ServerName/ReportServer_XXX/reportservice2010.asmx, (where I got ReportServer_XXX by remoting to the server and running the RS Config Manager). Then I’m able to do:

var rs = new ReportingService.ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// etc.

The next step is to add a web reference to the ReportExecutionService, which is what has the Render() method to actually output the PDF as an array of bytes. However, when I type in the URL: http://ServerName/ReportServer_XXX/reportexecutionservice2010.asmx (or ...2005.asmx), it brings up a heading of ServerName/ReportServer_XXX - / and under that the folders in our SSRS site (Chapters, Finance, Marketing, etc). The “Add Reference” button is grayed out.

What am I doing stoopid? Thanks!

like image 360
Amorphous Blob Avatar asked Nov 15 '25 09:11

Amorphous Blob


1 Answers

You are doing nothing stupid at all. However, you might want to change that URL to something like this.

ReportExecutionService rexec = new ReportExecutionService();
rexec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rexec.Url = "http://<your report server>/reportserver/ReportExecution2005.asmx";

I know that it's counter-intuitive. I am using SSRS 2017 and VS 2017 and it's still "2005". The following is SSRS boiler-plate from Microsoft:

string encoding = null;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rexec.ExecutionHeaderValue = execHeader;
execInfo = rexec.LoadReport(reportPath, historyID);
rexec.SetExecutionParameters(parameters, "en-us");
Console.WriteLine("SessionID: {0}", rexec.ExecutionHeaderValue.ExecutionID);
try
{
    Console.WriteLine(reportName.ToString());
    result = rexec.Render(format, devInfo, out string extension, out string 
        mimeType, out encoding, out warnings, out streamIDs);
    execInfo = rexec.GetExecutionInfo();
    Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
}
catch (SoapException e)
{
    Console.WriteLine(e.Detail.OuterXml);
    Dts.Events.FireError(0, "Error ",e.Message+ "\r" + e.StackTrace, String.Empty,0);
    Dts.TaskResult = (int)ScriptResults.Failure;
}
like image 121
Steve_Malcolm Avatar answered Nov 18 '25 01:11

Steve_Malcolm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!