Telerik blogs

The Telerik RESTful Reporting Service provides the ability to centralize an organization's reporting needs. This service is instrumental in extending the reach of your existing Telerik Reporting assets to include all modern desktop browsers as well as to mobile and other touch-friendly devices. In this blog post, I have outlined how to get a Telerik REST Reporting service up and running quickly. In subsequent blog posts, I will review how to consume the REST service to display reports in various technologies.

IMPLEMENTING THE REPORTING REST SERVICE

Open Visual Studio and create a new ASP.NET MVC 4 application, I’ve named mine StandAloneReportServer.

New Project Dialog

In the next screen, select ASP.NET Web API as the project type.

Now that the project has been created, it is time to add a couple of references. Add a reference to Telerik.Reporting and Telerik.Reporting.Services.WebApi. On these references, ensure the Copy Local property is set to true.



Next, right-click on the Controllers folder in Solution Explorer and select to create a new controller named ReportsController. Replace the source code of this file with the following code, which is also available in the help documentation:

using System.Web;
using Telerik.Reporting.Cache.Interfaces;
using Telerik.Reporting.Services.Engine;
using Telerik.Reporting.Services.WebApi;
 
public class ReportsController : ReportsControllerBase
{
 
    protected override IReportResolver CreateReportResolver()
    {
        var reportsPath =          HttpContext.Current.Server.MapPath("~/Reports");
 
        return new ReportFileResolver(reportsPath)
            .AddFallbackResolver(new ReportTypeResolver());
    }
 
    protected override ICache CreateCache()
    {
        return CacheFactory.CreateFileCache();
    }
}

The ReportsController is responsible for finding the requested report. In the CreateReportResolver method, you can see that we will first look in the Reports folder of our application for any report files that have been created using the Stand-Alone Telerik Report Designer tool, these files are saved with the extension *.trdx. If the requested report is not found there, it will fall back to looking for a compiled report represented as a C# class in all referenced assemblies using the ReportTypeResolver. The CreateCache method serves as an internal cache mechanism for the Reporting Engine. You can use either the file-based approach depicted in this example or by using a database.

Next we will need to register some routes. Open the Global.asax.cs file, and add the following using statement:

using Telerik.Reporting.Services.WebApi;

Then in the Application_Start method append the following line of code:

ReportsControllerConfiguration
        .RegisterRoutes(GlobalConfiguration.Configuration);

This is all that is required for the RESTful Telerik Report Service to run. What we need now is the actual reports. For this example, let’s create a Reports folder in Solution Explorer to hold Telerik Report Designer reporting files. Right-click the Reports folder and select Add Existing item, then navigate to the Telerik Report Designer samples (located in a location similar to C:\Program Files (x86)\Telerik\Reporting Q3 2013\Report Designer\Examples), select all the files and add them to the project. 

Adding Report Files

Next, navigate up one level from the examples (C:\Program Files (x86)\Telerik\Reporting Q3 2013\Report Designer) and copy the connection string for the reports from the Telerik.ReportDesigner.exe.config file, and paste it into the connection string section of the root Web.config file of our project.

<add name="Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString"
          connectionString= "Data Source=(local)\SQL2012;Initial Catalog=AdventureWorks;Integrated Security=SSPI"
          providerName="System.Data.SqlClient" />

SECURITY

We have received some questions regarding securing the Telerik RESTful Reporting Service. You should approach security as you would approach securing any ASP.NET Web API service. Currently you can easily add authorization at the ReportsController level by using the Authorize attribute from the System.Web.Http.AuthorizeAttribute namespace.

using System.Web;
using System.Web.Http;
using Telerik.Reporting.Cache.Interfaces;
using Telerik.Reporting.Services.Engine;
using Telerik.Reporting.Services.WebApi;
 
[Authorize]
public class ReportsController : ReportsControllerBase
{
...

WRAP-UP

Remember that you are free to clean up any of the boiler plate controllers and associated views that the ASP.NET Web API template generated that you are not using (namely Values and Home). In this blog post you saw how easy it was to get a Telerik RESTful Reporting Service up and running. Stay tuned to see how we use this service to serve up reports to various user interface technologies.

Download Source Code

View Video

Download Telerik Reporting


About the Author

Carey Payette

Carey Payette is a Senior Software Engineer with Trillium Innovations (a Solliance partner), an ASPInsider, a Progress Ninja, a Microsoft Certified Trainer and a Microsoft Azure MVP. Her primary focus is cloud integration and deployment for the web, mobile, big data, AI, machine learning and IoT spaces. Always eager to learn, she regularly tinkers with various sensors, microcontrollers, programming languages and frameworks. Carey is also a wife and mom to three fabulous boys.

Comments

Comments are disabled in preview mode.