Progress® Telerik® Reporting R2 2017

How To: Implement the ReportsController in an application

The Telerik Reporting REST Web API service is represented by the abstract ReportsControllerBase class. This abstract class requires IReportResolver and ICache implementations. In order to add the reports controller to your application follow the steps:

  1. Add references to the following Telerik Reporting assemblies (required) and set their Copy Local properties to true in Visual Studio:

    • Telerik.Reporting

    • Telerik.Reporting.Services.WebApi (located in the installation Bin folder)

    Note Note

    Without setting Telerik Reporting references' Copy Local to true the assemblies may not be loaded correctly on running the application.

  2. Add references to the following Telerik Reporting assemblies (optional) and set their Copy Local properties to true in Visual Studio:

    Note Note

    Without setting Telerik Reporting references' Copy Local to true the assemblies may not be loaded correctly on running the application.

  3. Inherit this base class in your hosting application (usually in the Controllers folder of a MVC application).

    ReportsControllerBase configuration in code:

    • Set the ReportServiceConfiguration property. The ReportResolver and Storage configuration settings are required. See the IReportServiceConfiguration interface for more details.

      using System.Web;
      using Telerik.Reporting.Services.WebApi;
      
      public class ReportsController : ReportsControllerBase
      {
          static Telerik.Reporting.Services.ReportServiceConfiguration configurationInstance =
              new Telerik.Reporting.Services.ReportServiceConfiguration
              {
                  HostAppId = "Application1",
                  ReportResolver = new ReportFileResolver(HttpContext.Current.Server.MapPath("~/Reports"))
                      .AddFallbackResolver(new ReportTypeResolver()),
                  Storage = new Telerik.Reporting.Cache.File.FileStorage(),
              };
      
          public ReportsController()
          {
              this.ReportServiceConfiguration = configurationInstance;
          }
      }

      ReportsControllerBase inherits System.Web.Http.ApiController and implements all necessary API actions.

      The provided sample implementation will resolve .trdx|.trdp report definitions from the Reports subfolder of the hosting ASP.NET application root. Other option is to reference a reports library and provide report type assembly qualified name from the service clients.

      Note Note

      Do not forget to add all necessary (i.e., referred from the report definitions) connection strings to the application configuration file.

      Tip Tip

      The above implementation uses the FileStorage method in order to create a cache object instance. All Visual Studio item templates for adding the Reporting REST service use the default FileStorage constructor. The second overload of the FileStorage constructor allows you to specify a folder, and it is recommended for usage in production environment.

    ReportsControllerBase configuration in configuration file:

    • To configure the Telerik Reporting REST service from the application configuration file, set the value of the ReportServiceConfiguration property to an instance of the ConfigSectionReportServiceConfiguration class.

      public class ReportsController : ReportsControllerBase
      {
          static Telerik.Reporting.Services.ConfigSectionReportServiceConfiguration configSectionConfigurationInstance =
              new Telerik.Reporting.Services.ConfigSectionReportServiceConfiguration();
      
          public ReportsController()
          {
              this.ReportServiceConfiguration = configSectionConfigurationInstance;
          }
      }
    • Then add the restReportService configuration element containing the service settings to the Telerik Reporting Configuration Section.

      <Telerik.Reporting>
        <restReportService hostAppId="Application1" reportSharingTimeout="10" clientSessionTimeout="10">
          <reportResolver provider="type" />
          <storage provider="file" />
        </restReportService>
      </Telerik.Reporting>

      For more information see restReportService Element.