# Adding 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.

> 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](https://www.nuget.org/packages/ServiceStack/3.9.70) 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):

   * `Telerik.Reporting.Cache.Database.dll` - only if [DatabaseStorage](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.cache.database.databasestorage) caching mechanism is intended. For more details check [Reporting REST Service Storage](https://www.telerik.com/products/reporting/documentation/embedding-reports/host-the-report-engine-remotely/rest-service-storage/overview). The assembly has dependencies on Telerik Data Access which can be checked in the version corresponding [Upgrade article](https://www.telerik.com/products/reporting/documentation/upgrade/overview);
   * `Telerik.Reporting.OpenXmlRendering.dll` - depends on [Third-Party Dependencies](https://www.telerik.com/products/reporting/documentation/getting-started/installation/third-party-dependencies). Required if you need to export in OpenXML formats (DOCX, PPTX, XLSX);
   * `Telerik.Reporting.XpsRendering.dll` - required if you need to export in XPS format;
   * `Telerik.Reporting.Adomd.dll` - required if you use [CubeDataSource](https://www.telerik.com/products/reporting/documentation/designing-reports/connecting-to-data/data-source-components/cubedatasource-component/overview) components in reports. The assembly has dependencies on *Microsoft.AnalysisServices.AdomdClient.dll* v.10.0.0.0 or [above with proper binding redirects](https://www.telerik.com/products/reporting/documentation/designing-reports/connecting-to-data/data-source-components/cubedatasource-component/configuring-your-project-for-using-microsoft-analysis-services);

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

   * Set the `ReportServiceConfiguration` property. The **ReportSourceResolver** and **Storage** configuration settings are required. See the [IReportServiceConfiguration](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.services.ireportserviceconfiguration) interface for more details.

     Here is a sample implementation with the setup:

     ```C#
     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.UriReportSourceResolver(reportsPath)
     			.AddFallbackResolver(new Telerik.Reporting.Services.TypeReportSourceResolver());

     		var reportServiceConfiguration = new Telerik.Reporting.Services.ReportServiceConfiguration();
     		reportServiceConfiguration.HostAppId = "Application1";
     		reportServiceConfiguration.ReportSourceResolver = resolver;
     		reportServiceConfiguration.Storage = new Telerik.Reporting.Cache.File.FileStorage();

     		this.ReportServiceConfiguration = reportServiceConfiguration;
     	}
     }
     ```

     ```VB.NET
     Imports Telerik.Reporting.Services

     Public Class ReportsHost
     		Inherits Telerik.Reporting.Services.ServiceStack.ReportsHostBase
     	Public Sub New()
     		Dim reportsPath = System.Web.HttpContext.Current.Server.MapPath("~\Reports")
     		Dim resolver = New UriReportSourceResolver(reportsPath) _
     					.AddFallbackResolver(New TypeReportSourceResolver())

     		Dim reportServiceConfiguration = New ReportServiceConfiguration()
     		reportServiceConfiguration.HostAppId = "Application1"
     		reportServiceConfiguration.ReportSourceResolver = resolver
     		reportServiceConfiguration.Storage = New Telerik.Reporting.Cache.File.FileStorage()
     		
     		Me.ReportServiceConfiguration = reportServiceConfiguration
     	End Sub
     End Class
     ```

     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](https://learn.microsoft.com/en-us/dotnet/api/system.type.assemblyqualifiedname?view=net-7.0#System_Type_AssemblyQualifiedName) from the service clients.

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

     > tip The above implementation uses the [FileStorage](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.cache.file.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.

   * Alternatively, you may **configure the Telerik Reporting REST service from the application configuration file**.

     If you prefer this approach, set the value of the `ReportServiceConfiguration` property to an instance of the [ConfigSectionReportServiceConfiguration](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.services.configsectionreportserviceconfiguration) class.

     ```C#
     public class ReportsHost : Telerik.Reporting.Services.ServiceStack.ReportsHostBase
     {
     public ReportsHost()
     {
     	var reportServiceConfiguration = new Telerik.Reporting.Services.ConfigSectionReportServiceConfiguration();

     	this.ReportServiceConfiguration = reportServiceConfiguration;
     }
     }
     ```

     ```VB.NET
     Public Class ReportsHost
     Inherits Telerik.Reporting.Services.ServiceStack.ReportsHostBase
     Public Sub New()
     	Dim reportServiceConfiguration = New Telerik.Reporting.Services.ConfigSectionReportServiceConfiguration()

     	Me.ReportServiceConfiguration = reportServiceConfiguration
     End Sub
     	End Class
     ```

     Then, add the **restReportService** configuration element containing the service settings to the [Telerik Reporting Configuration Section](https://www.telerik.com/products/reporting/documentation/doc-output/configure-the-report-engine/overview).

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

     For more information, see [restReportService Element](https://www.telerik.com/products/reporting/documentation/doc-output/configure-the-report-engine/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:

   ```C#
   protected void Application_Start()
        {
            new ReportsHost().Init();
        }
   ```

   ```VB.NET
   Protected Sub Application_Start()
        Dim reportsHost As New ReportsHost()
        reportsHost.Init()
    End Sub
   ```

7. Update the configuration file (*web.config*) to include the following *location* element:

   ```XML
   <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](https://www.telerik.com/products/reporting/documentation/embedding-reports/host-the-report-engine-remotely/rest-api-reference/general-api/get-available-document-formats).

## See Also

* [UriReportSourceResolver](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.services.urireportsourceresolver)
* [TypeReportSourceResolver](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.services.typereportsourceresolver)
* [HTML5 Report Viewer](https://www.telerik.com/products/reporting/documentation/embedding-reports/display-reports-in-applications/web-application/html5-report-viewer/overview)
* [Overview](https://www.telerik.com/products/reporting/documentation/embedding-reports/host-the-report-engine-remotely/rest-service-report-source-resolver/overview)
* [Manual Setup](https://www.telerik.com/products/reporting/documentation/embedding-reports/display-reports-in-applications/web-application/html5-report-viewer/manual-setup)
