Hosting the Telerik Reporting REST Service in an ASP.NET Application
In this case, the Web API will be hosted on top of the classic ASP.NET hosting infrastructure, supported by the IIS (Internet Information Services) server. The REST service setup can be done either by using the Telerik Reporting REST Service project template or manually, as explained below.
Using the REST Service Project Template
In Visual Studio, open the Add New Project dialog and select the Telerik Reporting REST Service (.NET Framework) project template, which appears when selecting the Reporting category from the left pane. This will add a new project in your solution that contains all the necessary files and packages to host the Telerik Reporting REST service instance.
The project has a preconfigured implementation of the reports controller that uses the ~\Reports path for its report source resolver. This directory is not automatically created and needs to be created, or the path to be modified accordingly, prior to running the project.
Manually Configuring the Telerik Reporting REST Service on IIS
-
In Visual Studio, create the hosting project. That might be one of the following project templates: ASP.NET Empty Web Application, ASP.NET Web Forms Application, ASP.NET MVC Web Application.
-
(Only for Empty Web Application / Web Forms Application) Install the
Microsoft.AspNet.WebApi.WebHostNuGet package (WebAPI 2, version 5.2.x or later is recommended). Besides the required assemblies, this will add the necessary handlers to theWeb.config:CONFIG<handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers>Because the Reporting REST WebAPI Service was originally built against WebAPI 1, when you reference a newer version of
Microsoft.AspNet.WebApi.WebHost(orMicrosoft.AspNet.WebApi.SelfHost) you have to redirectSystem.Web.HttpandSystem.Net.Http.Formattingto the newer version. The Visual Studio NuGet Package Manager can add the required binding redirects automatically when you update NuGet packages through it. Alternatively, add the followingbindingRedirectsto yourWeb.configand replace5.1.0.0in the sample with the exact version of the WebAPI assemblies referenced by your project:XML<?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Http" culture="neutral" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="5.1.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Formatting" culture="neutral" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="5.1.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>Legacy WebAPI 1 baseline. Existing projects still on WebAPI 1 can install the
Microsoft.AspNet.WebApi.WebHost 4.0.30506NuGet package instead. The same handler entries shown above will be added to theWeb.config, and no binding redirects are required for that baseline. -
Make sure that the project has the following assembly references:
Newtonsoft.Json.dllSystem.Web.Http.dllSystem.Web.Http.WebHost.dllSystem.Net.Http.dllSystem.Net.Http.Formatting.dll
-
(Only for Empty Web Application) Add a new item Global Application Class.
-
Invoke RegisterRoutes at the beginning of the
Global.Application_Start (Global.asax)method:C#protected void Application_Start() { ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration); -
Run the application
-
To verify whether the service works correctly, you can request the available document formats using the following URL:
http://localhost:[portnumber]/api/reports/formatsIf the request is successful, you should receive the document formats encoded in JSON. For more information, see: Get Available Document Formats.
The call to
http://localhost:[portnumber]/api/reports/formatsdoes not require authorization by design, as this request is for test purposes, i.e., to check whether the REST Service is running. -
Enable Cross-Origin Resource Sharing (CORS) (optional)
-
Add the
Microsoft.AspNet.WebApi.CorsNuGet package to the project. It may add other required references. It may be necessary to upgrade some of the already installed packages. -
Add the following code at the beginning of the
Global.Application_Start(Global.asax) method:C#GlobalConfiguration.Configuration.EnableCors(); -
Add the following attribute to the
ReportsControllerclass (requires reference toSystem.Web.Http.Cors):C#[EnableCors("*", "*", "*")] public class ReportsControllerCors : ReportsControllerBase
-
Next Steps
- Implement the
ReportsControllerin an ASP.NET application - Use the HTML5 Report Viewer with the Telerik Reporting REST Service