ad
ad
Topview AI logo

How to Create an ASP NET Core Web API Reporting Service App Video

Howto & Style


Introduction

In this article, we will guide you through the process of creating an ASP.NET Core Web API reporting service application that integrates with Bold Report Viewer. This centralized reporting solution provides an efficient way to process, generate, and deliver reports across various platforms while managing data effectively. Furthermore, this application can be hosted in diverse environments, including Kestrel, IIS, HTTP.sys, Nginx, and Docker.

Step 1: Setting Up the Application

Begin by creating a new application. Open your terminal or command prompt and run the following command to name your project:

dotnet new webapi -n CoreApiService

Once the application is created, navigate to the application's root folder by changing the current working directory:

cd CoreApiService

Next, install the necessary NuGet packages for the application. Add the Bold Reports.NET Core package by running the command:

dotnet add package BoldReports.AspNetCore

Step 2: Add Resources for Reports

Create a folder named resources within the wwwroot directory to store the RDL reports. We will use the SalesOrderDetails.rdl file for this tutorial. Add this file to the resources folder; you can find the download link in the video description.

Step 3: Configuring the Web API

Now, configure your Web API. Create a new controller file named ReportViewerController.cs. Add the necessary using statements and namespaces. Below are the namespaces you'll need to include:

using BoldReports.Web.ReportViewer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.Memory;
using System.IO;

Setting Up the Controller

Define the ReportViewerController class, inheriting from the appropriate controller and implementing the IReportController interface. This will help handle the report viewing logic.

Add the [Route("api/[controller]")] attribute to denote the controller's root and enable CORS by adding the [EnableCors] attribute.

Step 4: Implementing Report Processing Methods

Within the ReportViewerController, you’ll need to implement several action methods to handle the report requests.

  1. Post Report: Create a method to process report requests from the server.

  2. OnInitReportOptions: This method is triggered when the report is about to be processed. Load the report as a stream here.

  3. OnReportLoaded: Implement this method to handle loading of the report and its sub-reports.

  4. GetResource: This will enable the retrieval of images used in the report when previewing.

  5. PostFormReport: Finally, implement this method to handle exporting the report back to the client.

Step 5: License Registration

To avoid license validation messages, add the code to register your online license token in the Program.cs file. You can obtain license tokens from the Bold Reports accounts page.

BoldReports.ReportViewer.ReportViewerLicense.Key = "YOUR_LICENSE_KEY";

Step 6: Enable CORS

To allow access from different domains, implement the AddCors method in your service container registration and call UseCors in your app's middleware pipeline.

Step 7: Running and Testing the Application

Execute your application, and a URL will be generated. To test the ASP.NET Core Web API application, create a simple HTML/JavaScript client that integrates with the report viewer control. Ensure that the localhost URL matches where your report service is running.

Conclusion

In this tutorial, we successfully created an ASP.NET Core Web API reporting service application utilizing the Bold Report Viewer.

If you found this article helpful, please consider giving it a thumbs up and subscribing for more tutorials.


Keywords

  • ASP.NET Core
  • Web API
  • Reporting Service
  • Bold Reports
  • Report Viewer
  • CORS
  • License Registration
  • RDL Files

FAQ

Q1: What technologies are required to create this reporting service application?

A1: You will need ASP.NET Core, Visual Studio, and Bold Reports library to create the reporting service application.

Q2: Can this application be hosted on different environments?

A2: Yes, the application can be hosted in various environments, including Kestrel, IIS, HTTP.sys, Nginx, and Docker.

Q3: How do I enable Cross-Origin requests?

A3: You can enable CORS by implementing the AddCors method and calling UseCors in your application's middleware pipeline.

Q4: Where can I find the RDL files?

A4: You can find the SalesOrderDetails.rdl file download link in the description of the video associated with this article.

Q5: How do I register the Bold Reports license?

A5: You can register your license key in the Program.cs file of your application by using the provided syntax for license registration.