New to Telerik ReportingStart a free 30-day trial

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

  1. 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.

  2. (Only for Empty Web Application / Web Forms Application) Install the Microsoft.AspNet.WebApi.WebHost NuGet package (WebAPI 2, version 5.2.x or later is recommended). Besides the required assemblies, this will add the necessary handlers to the Web.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 (or Microsoft.AspNet.WebApi.SelfHost) you have to redirect System.Web.Http and System.Net.Http.Formatting to 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 following bindingRedirects to your Web.config and replace 5.1.0.0 in 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.30506 NuGet package instead. The same handler entries shown above will be added to the Web.config, and no binding redirects are required for that baseline.

  3. Make sure that the project has the following assembly references:

    • Newtonsoft.Json.dll
    • System.Web.Http.dll
    • System.Web.Http.WebHost.dll
    • System.Net.Http.dll
    • System.Net.Http.Formatting.dll
  4. Implement the ReportsController in your application

  5. (Only for Empty Web Application) Add a new item Global Application Class.

  6. Invoke RegisterRoutes at the beginning of the Global.Application_Start (Global.asax) method:

    C#
    protected void Application_Start()
    {
        ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration);
  7. Run the application

  8. To verify whether the service works correctly, you can request 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.

    The call to http://localhost:[portnumber]/api/reports/formats does not require authorization by design, as this request is for test purposes, i.e., to check whether the REST Service is running.

  9. Enable Cross-Origin Resource Sharing (CORS) (optional)

    1. Add the Microsoft.AspNet.WebApi.Cors NuGet package to the project. It may add other required references. It may be necessary to upgrade some of the already installed packages.

    2. Add the following code at the beginning of the Global.Application_Start (Global.asax) method:

      C#
      GlobalConfiguration.Configuration.EnableCors();
    3. Add the following attribute to the ReportsController class (requires reference to System.Web.Http.Cors):

      C#
      [EnableCors("*", "*", "*")]
      public class ReportsControllerCors : ReportsControllerBase

Next Steps

See Also