开发者

Load SSRS Report from file in C# in a service

开发者 https://www.devze.com 2023-04-01 17:35 出处:网络
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.

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.
  • Ca开发者_开发百科n 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消