New to Telerik Reporting? Download free 30-day trial

Implementing the ReportsController in an ASP.NET Application

The Telerik Reporting REST Web API service is represented by the abstract ReportsControllerBase class. This abstract class requires IReportSourceResolver and IStorage 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)
  2. Add references to the following Telerik Reporting assemblies (optional) and set their Copy Local properties to true in Visual Studio:

    • Telerik.Reporting.Cache.Database.dll - only if DatabaseStorage caching mechanism is intended. For more details check Reporting REST Service Storage. The assembly has dependencies on Telerik Data Access which can be checked in the version corresponding Upgrade article;
    • Telerik.Reporting.OpenXmlRendering - depends on Third-Party Dependencies. Required if you need to export in OpenXML formats (DOCX, PPTX, XLSX);
    • Telerik.Reporting.XpsRendering - required if you need to export in XPS format;
    • Telerik.Reporting.Adomd.dll - required if you use CubeDataSource components in reports. The assembly has dependencies on Microsoft.AnalysisServices.AdomdClient.dll v. or above with proper binding redirects;

    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 ReportSourceResolver and Storage configuration settings are required. See the IReportServiceConfiguration interface for more details.

      using System.Web;
      using Telerik.Reporting.Services;
      using Telerik.Reporting.Services.WebApi;
      public class ReportsController : ReportsControllerBase
          static readonly ReportServiceConfiguration configurationInstance =
              new ReportServiceConfiguration
                  HostAppId = "Application1",
                  ReportSourceResolver = new UriReportSourceResolver(HttpContext.Current.Server.MapPath("~/Reports"))
                      .AddFallbackResolver(new TypeReportSourceResolver()),
                  Storage = new Telerik.Reporting.Cache.File.FileStorage(),
          public ReportsController()
              this.ReportServiceConfiguration = configurationInstance;
      Imports System.Web
      Imports Telerik.Reporting.Cache.Interfaces
      Imports Telerik.Reporting.Services
      Imports Telerik.Reporting.Services.WebApi
      Imports System.Net
      Imports System.Net.Mail
      Public Class ReportsController
          Inherits ReportsControllerBase
          Shared ReadOnly configurationInstance As ReportServiceConfiguration
          Shared Sub New()
              Dim resolver = New UriReportSourceResolver(HttpContext.Current.Server.MapPath("~/Reports")) _
                             .AddFallbackResolver(New TypeReportSourceResolver())
              Dim reportServiceConfiguration As New ReportServiceConfiguration()
              reportServiceConfiguration.HostAppId = "Application1"
              reportServiceConfiguration.ReportSourceResolver = resolver
              reportServiceConfiguration.Storage = New Telerik.Reporting.Cache.File.FileStorage()
              configurationInstance = reportServiceConfiguration
          End Sub
          Public Sub New()
              Me.ReportServiceConfiguration = configurationInstance
          End Sub
          Protected Overrides Function CreateCache() As ICache
              Return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache()
          End Function

      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.

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

      The above implementation uses the FileStorage method in order to create a storage 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;
      Public Class ReportsController
          Inherits ReportsControllerBase
          Shared configSectionConfigurationInstance As New Telerik.Reporting.Services.ConfigSectionReportServiceConfiguration()
          Public Sub New()
              Me.ReportServiceConfiguration = configSectionConfigurationInstance
          End Sub
      End Class

      Then add the restReportService configuration element containing the service settings to the Telerik Reporting Configuration Section.

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

      For more information see restReportService Element.

In this article