Progress® Telerik® Reporting R3 2017

How To: Add Telerik Reporting REST ServiceStack to Web Application

This article describes the steps required to host the Telerik Reporting ServiceStack REST Service implementation on top of the classic ASP.NET hosting infrastructure supported by the IIS (Internet Information Services) server.

Note Note

Telerik Reporting ServiceStack assembly requires V3 of the ServiceStack framework.

How to host the ServiceStack implementation of Telerik Reporting REST service in IIS:

  1. Create a new ASP.NET Empty Web Application.

  2. Install the ServiceStack 3.9.70.0 NuGet package.

  3. Add references to the following Telerik Reporting assemblies (required):

    • Telerik.Reporting.dll

    • Telerik.Reporting.Services.ServiceStack.dll

  4. Add references to the following Telerik Reporting assemblies (optional):

  5. Create a new class which derives from ReportsHostBase. It could be called ReportsHost for example:

    Here is a sample implementation with the setup:

    public class ReportsHost : Telerik.Reporting.Services.ServiceStack.ReportsHostBase
    {
        public ReportsHost()
        {
            var reportsPath = System.Web.HttpContext.Current.Server.MapPath(@"~\Reports");
            var resolver = new Telerik.Reporting.Services.ServiceStack.ReportFileResolver(reportsPath)
                .AddFallbackResolver(new Telerik.Reporting.Services.ServiceStack.ReportTypeResolver());
    
            var reportServiceConfiguration = new Telerik.Reporting.Services.ReportServiceConfiguration();
            reportServiceConfiguration.HostAppId = "Application1";
            reportServiceConfiguration.ReportResolver = resolver;
            reportServiceConfiguration.Storage = new Telerik.Reporting.Cache.File.FileStorage();
    
            this.ReportServiceConfiguration = reportServiceConfiguration;
        }
    }

    The provided sample implementation will resolve .trdp|.trdx report definitions from the /Reports subfolder of the hosting ASP.NET application root. Another 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.

    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 ReportsHost : Telerik.Reporting.Services.ServiceStack.ReportsHostBase
    {
        public ReportsHost()
        {
            var reportServiceConfiguration = new Telerik.Reporting.Services.ConfigSectionReportServiceConfiguration();
    
            this.ReportServiceConfiguration = reportServiceConfiguration;
        }
    }

    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.

  6. Add a new or use the existing Global Application Class (global.asax) to create and initialize the ServiceStack reports service in the Application_Start method:

    protected void Application_Start()
    {
        new ReportsHost().Init();
    }
  7. Update the configuration file (web.config) to include the following location element:

    <configuration>
     <location path="api">
        <system.web>
         <compilation debug="true" targetFramework="4.0" />
         <httpHandlers>
           <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
         </httpHandlers>
        </system.web>
        <system.webServer>
         <modules runAllManagedModulesForAllRequests="true"/>
         <validation validateIntegratedModeConfiguration="false"/>
         <handlers>
           <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
         </handlers>
        </system.webServer>
     </location>
    </configuration>
  8. To verify whether the service works correctly you can make a sample request for the available document formats using the following url:

    http://localhost:[portnumber]/api/reports/formats

    If the request is successful you should receive the document formats encoded in JSON. For more information see: Get Available Document Formats.

See Also