How to use SSRS 2017, 2019 REST API to render report and save as pdf programmatically

Pengxin Fan 116 Reputation points
2021-01-08T11:05:28.333+00:00

I have a UIAPI project which use to generate SSRS reports and save as PDF file programmatically by using reportexecution2005.asmx web service with user credentials.

It works for SSRS 2016, but failed to SSRS 2017 or later.

I understand that the SSRS 2017 has provided a new feature: REST API to access SSRS objects. But I couldn't find how to use it to render reports and save as PDF file with users credentials.

Could you please give me some guidance how to make it work?

Many thanks

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,065 questions
{count} votes

Accepted answer
  1. Pengxin Fan 116 Reputation points
    2021-01-11T09:37:19.953+00:00

    Thank you very much @Joyzhao-MSFT for your reply. That is helpful, but haven't resolved my issue completely.

    There are still two issues which haven't clear.

    1. How to pass user's credential with URL access, such as reportexecution2005.asmx using to?
      ReportExecutionService rs = new ReportExecutionService();
      rs.Credentials = new NetworkCredential(
      SsrsServiceAccountActiveDirectoryUserName,
      SsrsServiceAccountActiveDirectoryPassword,
      SsrsServiceAccountActiveDirectoryDomain);
          rs.Url = ReportExecution2005EndPointUrl;  
          rs.ExecutionHeaderValue = new ExecutionHeader();  
      
    2. How to save this PDF file as byte[], such as
      private static byte[] RenderReportBytes(ReportExecutionService rs)
      {
      string deviceInfo = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
      string mimeType;
      string encoding;
      string[] streamId;
      Warning[] warning;
          var result = rs.Render("PDF", deviceInfo, out mimeType, out encoding, out encoding, out warning, out streamId);  
          return result;  
      }  
      
      ?

    Many thanks


6 additional answers

Sort by: Most helpful
  1. Pengxin Fan 116 Reputation points
    2021-01-08T13:14:44.587+00:00

    Hi OlafHelper-2800,

    Thank you for your reply. I did read samples, but couldn't find any examples to resolve my issue.

    1 person found this answer helpful.
    0 comments No comments

  2. Joyzhao-MSFT 15,636 Reputation points
    2021-01-11T03:13:03.957+00:00

    Hi @Pengxin Fan ,
    As far as I know, there is no method available in RestAPI provided by Microsoft available here.
    There is an alternative to generate report by utilizing Url Access (SSRS)

    URL access to the report server in SQL Server Reporting Services (SSRS) enables you to send commands to a report server through a URL request.
    URL Access Syntax
    URL requests can contain multiple parameters that are listed in any order. Parameters are separated by an ampersand (&) and name/value pairs are separated by an equal sign (=).
    Export a Report Using URL Access
    You can optionally specify the format in which to render a report by using the rs:Format URL parameter. The HTML4.0 and HTM5 formats (rendering extension) will render in the browser and for other formats, the browser will prompt to save the report output to a local file.

    For example, to get a PDF copy of a report directly from a native mode report server:

    http://myrshost/ReportServer?/myreport&rs:Format=PDF  
    

    You can also provide parameters to this using syntax

    http://myrshost/ReportServer?/activeusers&UserStatus=true&rs:Format=PDF  
    

    For more details, please refer to: https://learn.microsoft.com/en-us/sql/reporting-services/export-a-report-using-url-access
    Best Regards,
    Joy


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. Olaf Helper 47,516 Reputation points
    2021-01-08T13:06:54.81+00:00
    0 comments No comments

  4. Pengxin Fan 116 Reputation points
    2021-01-19T10:26:52.15+00:00

    HI Joyzhao-MSFT,

    Looks like that will work. I will try it and let you know shortly.

    Many thanks,

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.