0
votes

I'm working on solution to generate SSRS report in memory to attach after as mail attachment. I'm using 2010 version.

Report has required parameters that should be filled to render report correct.

I found few solution how to do this:

Solution 1

Using MS native ReportViewer class. We can instantiate object in memory, connect to server and render report in required format using control API

report.ServerReport.ReportServerCredentials = new MyCredentials(...);
report.ServerReport.ReportServerUrl = new Uri("ssrs_url");
report.ServerReport.ReportPath = "path-to-report";

byte[] reportData = report.ServerReport.Render("excel");

The solution have main drawback - it requires significant set of dependencies to use reporting control. So it hard to use in layered architecture, when lower layers have limited and predefined set of dependencies to be loose coupled and be easy ported to wide range OS'es and cloud stacks.

So can't adopt this solution in my case

Solution 2

Use report server public API to access data already in required format. I found out that this can be achieved and MS confirms this. Here is link https://msdn.microsoft.com/en-us/library/ms154040.aspx

So we can just use right configured link to access data: http://myrshost/ReportServer?/myreport&rs:Format=PDF

This solution best suited for my needs, but I don't know how to pass report parameters to this report? Also how to authenticate first against SSRS report server?

Can someone help me with this?

1
Is consuming the ReportingServices webservice an option? Depending on your version of SSRS (you may include it in your post), you can find the service asmx here: myrshost:80/ReportServer/ReportExecution2005.asmx. - Chris Schmitz
Yes, I have all data required. How to pass data to specific report parameters. I have required properties to be filled before rendeing report - VadimB
Having an appointment now, will come back to you later (if nobody else is faster ;)) Have a look at MSDN for the service in the mean time. msdn.microsoft.com/en-us/library/ms152787.aspx - Chris Schmitz

1 Answers

3
votes

So, finally made it to write an answer.

First of all: Sadly i couldn't find any way to include parameters when using the simple URL Access of the reports. I haven't really worked with that yet. So there might be another (better) solution for your specific case.

Regarding your restrictions stated in your first solution: I actually don't see what "Framework" you are using for that but if you can't use it anyway, it's irrelevant.

What i'd suggest you, is using the SSRS WebServices, as i already stated in my comments. Basic information about that can be found here. Basically you only have some simple steps to do:

  1. Consume the WebService (it's a SOAP service) and let Visual Studio (.NET) generate the proxy classes for you. There is a wide range of tutorials for that in the web. For example this one. I don't see any problems with dependencies here, because it's only a WebService.

  2. Then you are already able to call the WebService. The proxy generated all necessary classes for you.

The following example demonstrates the call, and also how the parameters are passed to the WebService (which of course, is easily possible). Please note that the example is written for the ReportExecution2005.asmx. There might be differences in the newest version.

var client = new ReportExecutionService();
client.Url = "UrlToReportExecutionASMXonYourServer";
client.Credentials = yourCredentials // (is of type System.Net.ICredentials)

client.LoadReport2("RelativePathToYourReportOnServer", null);

var parameters = new ParameterValue[amountOfYourParameters];
parameters[0] = new ParameterValue() { Name = "ParamNameInReport", Value = "Value" };
client.SetExecutionParameters(parameters, CultureInfo.CurrentCulture.Name.ToLowerInvariant());

string encoding, mimeType, extension, deviceInfo;
Warning[] warnings;
string[] streamIDs;
var result = client.Render("ExportFormatOfDesiredResult", deviceInfo,  out extension, out encoding, out mimeType, out warnings, out streamIDs);

"ExportFormatOfDesiredResult" can be replaced with "Xml", "Pdf", "Word", etc. for example. i Your result will then be a byte stream which you can return to your client, attach to mail or whatever you want to do with that.

I hope this helps you. Feel free to ask for further assistence or let me know, if this isn't suiting your needs for any reason. (Please add a detailed description of your architecture and it's restrictions then, as i currently don't understand what exactly you need and what you can't do.)