FlexReport for .NET | ComponentOne
Reports in Web / Configure FlexReport WebAPI / Using Standard Visual Studio WebAPI Template
In This Topic
    Using Standard Visual Studio WebAPI Template
    In This Topic

    Complete the following steps to configure FlexReport Web API using standard Visual Studio Template for Web API:

    Configure Web API Project

    Complete the following steps to configure Web API project:

    1. Create a new ASP.NET Web API Project.
    2. Add the FlexReport Web API package from NuGet Package Manager.
      If you have installed MVC Edition or any other edition using ComponentOneControlPanel, the following NuGet source path gets already set inside Visual Studio.

      NuGet source path in NuGet Package Manager

      Alternatively, you can manually add the source path from NuGet Package Manager | Package Sources option available in Options dialog box, which appears on selecting Tools | NuGet Package Manager | Package Manager Settings.
      In the NuGet package manager the Report Service is listed as shown in the following image:

      NuGet Package Manager

      FlexReport Web API adds all the corresponding references to the project.

    3. License your Web API application. Create a licenses.licx file within Properties folder of your application and add the following code in it:
      licenses.licx
      Copy Code
      C1.Web.Api.LicenseDetector, C1.Web.Api
      

    Back to Top

    Add Report files to the Project

    1. Create a folder named Files in your application.
    2. Add the FlexReport Definition file to it.

      If the report is using any local database (such as MDB or MDF files), then add the database file to the App_Data folder of your project. However, make sure that the connection string of the reports are pointing to the App_Data folder accordingly.


    Back to Top

    Set Report's Root Location and Use C1 Web APIs

    1. Open the Startup.cs file and add the following code to Configuration method:
      Startup.cs
      Copy Code
      public void Configuration(IAppBuilder app)
      {
          app.UseCors(CorsOptions.AllowAll);
          var folder = GetFullRoot("Files");
          app.AddDiskStorage("root", folder);
          ConfigureAuth(app);
      }
      

             
      Note: Make sure you add Microsoft.Owin.Cors Nuget package in your application, for app.UseCors();
    2. Add the following GetFullRoot function in the startup class.
      Startup.cs
      Copy Code
      private static string GetFullRoot(string root)
              {
                      var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                      var fullRoot = Path.GetFullPath(Path.Combine(applicationBase, root));
                      if (!fullRoot.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
              {
                              fullRoot += Path.DirectorySeparatorChar;
      
              }
                      return fullRoot;
              }
      
    3. Open Web.Config and add the following entry under handlers inside system.webServer Node.
      Web.config
      Copy Code
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="api/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      

    Back to Top

    Deploy FlexReport Web API Service

    1. Compile the Project.
    2. Deploy the project to IIS.
      Observe that the Web API URL for service hosted on local IIS is created.
    Note: Once you have successfully created Web API URL for Report Services, you can access and view reports stored in the service using FlexViewer for MVC and Wijmo Viewer. For more information on how to view reports, see Configuring ReportViewer.