Using the SSRS web service: Requesting a report and rendering it

The SSRS web service can be a little opaque. Here’s a code example that shows how to connect to the service, request a report, and render it to an html file. You can use this pattern to request a report and write it out in any format you prefer (HTML, PDF, RDL etc.).

And remember to add the web reference to your SSRS ReportExecution2005 web service in Visual Studio. Note: this is separate from the ReportExecution2010 service and namespace.

//Create new ReportExecutionService instance and establish network credentials
ReportExecution2005.ReportExecutionService rs = new ReportExecution2005.ReportExecutionService();
rs.Credentials = new System.Net.NetworkCredential("your-user-name", "your-pass", "your-domain");
rs.Url = "http://yourip/yourreportserver/reportexecution2005.asmx";

// Render arguments

//set format string to whatever output you need–see MSDN documentation
//set devInfo value to TRUE if you just want the report div, otherwise FALSE for full html page
//sorry, had to upload image since WordPress freaks out with tags!

string format = "HTML4.0";

//You can enter report parameters below if you need to
//ParameterValue[] parameters = null;

byte[] result = null;
string reportPath = "/Sample Reports/yoursamplereport";
string historyID = null;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;

//Execute request
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();

rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

//Write results out to an html file
FileStream stream = File.Create(@"C:\report.html", result.Length);
stream.Write(result, 0, result.Length);

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: