Load SSRS Report from file in C# in a service

11,090

I'm not sure that this is an answer, but lets call it supporting material.

I have this code example from msdn that shows how you can do this by creating a service client and calling a given report as a PDF and saves it to file stream.

http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx

The problem I'm currently having is finding the correct client object to interact with after pointing VS to the SSRS service. The object I'm using to interact with the service is:

ReportExecutionServiceSoapClient rs = new ReportExecutionServiceSoapClient();

However, the interface doesn't match my code example. So this is a little closer, but not an answer.

UPDATE: The correct Proxy class generator

Here's the link to how to generate the proxy correctly. You'll need the windows sdk installed (current is 7.1). You can find that on microsoft.com, like I did. Execute the command line and it'll generate a file for you. Include in project:

http://msdn.microsoft.com/en-us/library/ms155134%28v=SQL.110%29.aspx

UPDATE: Got the thing workin

I just had to generate the correct proxy. Ok, so for SSRS 2010, apparently they split report execution and management out into two services. The only one I needed to generate my report from a C# console app was the execution service. Maybe that's totally obvious to everyone but me :) ?

Ok so open up a Windows SDK command shell and put this stuff in it for the execution service:

wsdl /language:CS /n:"Microsoft.SqlServer.ReportExecution" http://<Server Name>/reportserver/reportexecution2010.asmx?wsdl /o:"ReportExecution.cs"

Go to C:\Program Files\Microsoft SDKs\Windows\v7.1 and pick up your ReportExecution.cs file. Copy and paste it in your project.

Then you just have to say this:

Microsoft.SqlServer.ReportExecution.ReportExecutionService rsExec = 
                new Microsoft.SqlServer.ReportExecution.ReportExecutionService();
            rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
            rsExec.Url = @"http://<ServerName>/reportserver/ReportExecution2005.asmx";

Follow along the example from this link, which is the same one as above, and you should be generating some pretty awesome reports from your handy C# app.

Share:
11,090
Adriaan Stander
Author by

Adriaan Stander

I am passionate about people and culture, and believe that personal interest and development is the incubator for trust and purpose. I believe that coaching and mentorship is an ongoing process of self-improvement, a responsibility not taken lightly. In my spare time, I am also a passionate software engineer, mainly focusing on Visual Studio C# .Net, SQL Server, SSRS and Crystal Reports. I enjoy working with new technologies and cloud platforms such as AWS and Azure. AWS Certified Solutions Architect. I love reading and learning, and set myself high personal development goals. I believe that the edge of our comfort zone is where we truly stretch and grow.

Updated on June 05, 2022

Comments

  • Adriaan Stander
    Adriaan Stander almost 2 years

    We are looking into replacing Crystal with SSRS.

    I would like to know if it is at all possible to load the .rdl or .rdl.data file in C# and generate the report to a memory stream.

    I have seen some examples using the LocalReport, but this seems to be part of either the WinForms or WebForms assemblies.

    So what I would like to know is:

    • Is it possible to load the report from file as part of our service.
    • Can we then generate the report to a Stream (lets say a memory stream)
    • Can I do this without using the WebForms/WinForms assemblies in my service
    • Can we achieve this without using the webservice for SSRS