Reputation: 7092
I'm trying to connect to an SSRS server and get report data via .NET webClient. I'm doing this because I can't use forms and I don't want to just send the user to the report server. I'd rather keep everything in my web application.
So I have this bit of code in a controller:
public IHttpActionResult GetSpecs(int Id)
{
var client = new WebClient();
client.Credentials = new System.Net.NetworkCredential("username", "pw", "domain");
var data = client.DownloadString(ReportServerUrl + "?%2fFactory+Specs+Reports%2fSpecs_Stats_Matrix&rs:Command=Render&a=" + Id + "&b=" + CurrentUser.Id);
return Ok(data)
}
It successfully connects to the SSRS server, and it does get data. Inspecting the data, it looks like it's the report I need, but it's just one giant string of html and javascript that the SSRS server spits out.
My question is, is there a good way of handling this data?
I'm in unfamiliar territory, and it doesn't seem like a lot of people interact with SSRS in this way.
I'm not quite sure how to display all the data the end user.
Thanks!
Upvotes: 2
Views: 1924
Reputation: 1144
Thats quite easy. :)
First you need some assemblies to access the reporting service.
All these assemblies are easy to include in your project via Nuget,
After this you need to connect to your SSRS service instance like this:
using Microsoft.Reporting.WebForms;
CustomReportCredentials reportServerCredentials = new CustomReportCredentials("User", "Password", "REPORTINGSERVER");
ServerReport report = new ServerReport()
{
ReportServerUrl = new Uri("https://reporting.xxxx.com/ReportServer"),
ReportServerCredentials = reportServerCredentials,
ReportPath = "/Reports/MyReport",
Timeout = 200000
};
Ask the service for supported render extentions and generate the report:
var renderExtentions = report.ListRenderingExtensions();
report.SetParameters(new ReportParameter[]
{
new ReportParameter("parameter1", dcStringID.ToString()),
new ReportParameter("parameter2", begin.ToString()),
new ReportParameter("parameter3", end.ToString())
});
String mineType = String.Empty;
String fileNameExtention = String.Empty;
Stream stream = report.Render(renderExtentions.First(), null, null, out mineType, out fileNameExtention);
At this point you will have all you need. Stream, mine type, file extention.
Upvotes: 5