Reputation: 957
I have a link to an SRSS report which looks something like this https://enterprisereports.contoso.com/NA_REPORTS/report/HR/HR%20Department/Open/Roster
. When I open the report in a browser:
I'm trying to write c# code to automatically extract data from this report. Right now, I manually export data in excel by pressing save icon and use it as an input to my c# app but I'd like to automate this. Things I've tried:
https://server/reportserver/ReportService2010.asmx?wsdl
(source). I've tried https://enterprisereports.contoso.com/NA_REPORTS/report/HR/HR%20Department/Open/Roster/ReportService2010.asmx?wsdl
, https://enterprisereports.contoso.com/NA_REPORTS/report/ReportService2010.asmx?wsdl
, https://enterprisereports.contoso.com/NA_REPORTS/report/ReportService2010.asmx?wsdl
, https://enterprisereports.contoso.com/NA_REPORTS/ReportService2010.asmx?wsdl
and https://enterprisereports.contoso.com/ReportService2010.asmx?wsdl
- all I get is either 404 or the item cannot be found.https://<Report Server Name>/reportserver?/Sales/YearlySalesSummary&rs:Format=Excel&rs:Command=Render
(source). I've tried https://enterprisereports.contoso.com/NA_REPORTS/report/HR/HR%20Department/Open/Roster&rs:Format=Excel&rs:Command=Render
. I got thisThe path of the item /HR/HR Department/Open/Roster&rs:Format=Excel&rs:Command=Render' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath) Get Online Help
Is there an easy way to extract data from the report?
Note1: I'm new to SRSS.
Note2: I know that the report uses data stored somewhere (probably sql instance) but all I have is the link to the report. Getting access to the internal is not an option for me: 1) don't know who to ask 2) will be a long process 3) not sure the access would be granted :(.
Upvotes: 0
Views: 489
Reputation: 78568
The "ReportService2010" service is for management, not for rendering. You want the "ReportExecution2005" service.
The link to the report probably looks like this:
https://some_server_name.internal/Reports/Foldername/Reportname
You should then be able to find the report execution service at
https://some_server_name.internal/reportserver/ReportExecution2005.asmx?wsdl
I got this working by using a web reference, not a service reference, in visual studio, and the following code.
var rs = new ReportExecutionService();
rs.Url = "https://some_server_name.internal/reportserver/ReportExecution2005.asmx?wsdl";
rs.UseDefaultCredentials = false;
rs.Credentials = new System.Net.NetworkCredential(serviceUser, servicePassword, serviceDomain);
var execInfo = rs.LoadReport("/Foldername/Reportname", HistoryID: null);
// Set any data source credentials and parameters here
rs.SetExecutionCredentials(new[] {
new DataSourceCredentials() {
DataSourceName = datasourcename,
UserName = datasourceUser,
Password = datasourePassword
}
});
// Now, render to XML
var bytes = rs.Render("XML", DeviceInfo: null, out var ext, out var mimetype, out var encoding, out var warnings, out var streamids);
// The bytes will probably contain a BOM,
// so wrap in a memory stream and hand to parser,
// instead of going via a string.
var buffer = new MemoryStream(bytes);
var doc = XDocument.Load(buffer);
// Now you can extract the data you want from the XML.
// For now, maybe save it?
doc.Save("report-result.xml");
It's probably possible to get this working via a "Service reference", but I got stuck on authentication.
Also, note that the XML will follow the structure of the data sets in the report. So it might not look exactly like you expect, since no layout/filtering from the report layout will be applied.
Upvotes: 2