Q4 2024 changes - dnikolov (#1524)
* add info about AutoRun * update article for asp.net core reporting service with minimal apis * update info about skia * move the approach of setting up the asp.net core service with controllers into separate article * ReportsController article for ASP.NET Web APIs to include minimal approach * fix text
This commit is contained in:
Родитель
63176bf237
Коммит
d58b9042f3
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Hosting in .NET
|
||||
page_title: Hosting REST Service configuration in ASP.NET Core in Startup.cs
|
||||
title: Hosting in .NET with Main Method
|
||||
page_title: Hosting REST Service configuration in ASP.NET Core in with Main Method
|
||||
description: "Learn how to configure the Telerik Reporting REST Service in an ASP.NET Core application in .NET through the Visual Studio project template or manually when providing the Reporting configuraion in Startup.cs."
|
||||
slug: telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/asp.net-core-web-api-implementation/how-to-host-reports-service-in-asp.net-core-in-.net-5
|
||||
tags: how,to,host,reports,service,in,asp.net,core,in,.net
|
||||
|
@ -53,100 +53,65 @@ In this tutorial, the resulting service will use the sample report definitions d
|
|||
|
||||
> It is recommended to use declarative definitions (TRDP/TRDX/TRBP) authored using the [Standalone Report Designer]({%slug telerikreporting/designing-reports/report-designer-tools/desktop-designers/standalone-report-designer/overview%}) or the [Web Report Designer]({%slug telerikreporting/designing-reports/report-designer-tools/web-report-designer/overview%}) in order to take advantage of their design-time tooling because the VS integrated report designer tooling is still not available in .NET projects.
|
||||
|
||||
### Add the required dependencies
|
||||
### Add the Required Dependencies
|
||||
|
||||
This guide applies the recommended NuGet package references approach to add the dependencies:
|
||||
This guide applies the recommended NuGet package references approach to add the dependencies:
|
||||
|
||||
1. Reference the __Telerik.Reporting.Services.AspNetCore__ (or __Telerik.Reporting.Services.AspNetCore.Trial__) package.
|
||||
1. Optionally, to enable the Office OpenXML document formats (XLSX, DOCX and PPTX) as export options, reference the __Telerik.Reporting.OpenXmlRendering__ (or __Telerik.Reporting.OpenXmlRendering.Trial__) NuGet package.
|
||||
|
||||
> The recommended way of adding the necessary dependencies is to use the [Progress Telerik proprietary NuGet feed]({%slug telerikreporting/using-reports-in-applications/how-to-add-the-telerik-private-nuget-feed-to-visual-studio%}) and reference the dependencies as NuGet packages. This would also add the indirect dependencies to your project bringing easier dependency management. Alternatively, the assemblies are available in the `\Bin\net6.0\` folder of Telerik Reporting installation directory. However, this would require to manually add all indirect dependencies listed in [.NET Support - Requirements]({%slug telerikreporting/using-reports-in-applications/dot-net-core-support%}#requirements) section and also the following dependency package: [Microsoft.AspNetCore.Mvc.NewtonsoftJson version 5.0.0](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson) and [DocumentFormat.OpenXML version 2.7.2.0 or above](https://www.nuget.org/packages/DocumentFormat.OpenXml). Note that you need the last reference only to enable the Office OpenXML document formats. The Reporting engine relies on the GDI+ API which is available on the Windows OS. On Linux and macOS we use library called [libgdiplus](https://www.mono-project.com/docs/gui/libgdiplus) instead. The GDI+ API is required for measuring, laying out, rendering the text glyphs and images.
|
||||
> The recommended way of adding the necessary dependencies is to use the [Progress Telerik proprietary NuGet feed]({%slug telerikreporting/using-reports-in-applications/how-to-add-the-telerik-private-nuget-feed-to-visual-studio%}) and reference the dependencies as NuGet packages. This would also add the indirect dependencies to your project bringing easier dependency management.
|
||||
Alternatively, the assemblies are available in the `\Bin\net6.0\` and `\Bin\netstandard2.0\` folders of Telerik Reporting installation directory. However, this would require to manually add all indirect dependencies listed in [.NET Support - Requirements]({%slug telerikreporting/using-reports-in-applications/dot-net-core-support%}#requirements) section and also the following dependency package: [Microsoft.AspNetCore.Mvc.NewtonsoftJson version 5.0.0](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson/) and [DocumentFormat.OpenXML version 2.7.2.0 or above](https://www.nuget.org/packages/DocumentFormat.OpenXml/).
|
||||
Note that you need the last reference only to enable the Office OpenXML document formats. The Reporting engine relies on the [GDI+ API](https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-gdi-start) which is available on the Windows OS. On Linux and macOS we use the [SkiaSharp](https://github.com/mono/SkiaSharp) 2D Graphics Library based on Google's [Skia](https://skia.org/) Graphics Library.
|
||||
|
||||
### Setup the Startup.cs file for the Reports service
|
||||
|
||||
The `ConfigureServices` method inside the `Startup.cs` in the project should be modified in order to enable the Reports Service functionality.
|
||||
The [`ConfigureServices`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder.configureservices) method inside the `Startup.cs` file in the project should be modified in order to enable the Reports Service functionality.
|
||||
|
||||
1. Make sure the application is configured for WebAPI controllers and call the `AddNewtonsoftJson` on the IMvcBuilder object to place the NewtonsoftJson serialization:
|
||||
1. Call the [`AddNewtonsoftJson`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.newtonsoftjsonmvcbuilderextensions.addnewtonsoftjson) extension method on the [IMvcBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.imvcbuilder) object to enable the **NewtonsoftJson** serialization:
|
||||
|
||||
````C#
|
||||
services.AddControllers().AddNewtonsoftJson();
|
||||
services.AddNewtonsoftJson();
|
||||
````
|
||||
|
||||
|
||||
1. Add the dedicated configuration object needed from the Reports Service in the dependency container. Note how the report source resolver will target the Reports folder we created earlier.
|
||||
1. Set up the [ReportServiceConfiguration](/api/telerik.reporting.services.reportserviceconfiguration) by invoking the `AddTelerikReporting` extension method on the [IMvcBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.imvcbuilder) object. In the code below, the first argument will represent the [HostAppId](/api/telerik.reporting.services.reportserviceconfiguration#Telerik_Reporting_Services_ReportServiceConfiguration_HostAppId) of the [ReportServiceConfiguration](/api/telerik.reporting.services.reportserviceconfiguration) object, while the second is the path that will be passed to the [UriReportSourceResolver](/api/telerik.reporting.services.urireportsourceresolver).
|
||||
|
||||
````C#
|
||||
// Configure dependencies for ReportsController.
|
||||
services.TryAddSingleton<IReportServiceConfiguration>(sp =>
|
||||
new ReportServiceConfiguration
|
||||
{
|
||||
ReportingEngineConfiguration = ConfigurationHelper.ResolveConfiguration(sp.GetService<IWebHostEnvironment>()),
|
||||
HostAppId = "Net5RestServiceWithCors",
|
||||
Storage = new FileStorage(),
|
||||
ReportSourceResolver = new UriReportSourceResolver(
|
||||
System.IO.Path.Combine(sp.GetService<IWebHostEnvironment>().ContentRootPath, "Reports"))
|
||||
});
|
||||
````CSharp
|
||||
var reportsPath = Path.Combine(builder.Environment.ContentRootPath, "Reports");
|
||||
|
||||
services.AddTelerikReporting("ReportingNet", reportsPath);
|
||||
````
|
||||
|
||||
|
||||
1. Make sure the endpoints configuration inside the `Configure` method of the `Startup.cs` are configured for API controllers by adding the following line in the lambda expression argument:
|
||||
1. Register the Telerik Reportig Minimal API by invoking the `UseTelerikReporting` extension method on the [WebApplication](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.webapplication) object. The application must also enable the endpoint routing middleware added by the [UseRouting](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.endpointroutingapplicationbuilderextensions.userouting) method:
|
||||
|
||||
````C#
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
//...
|
||||
});
|
||||
````CSharp
|
||||
app.UseTelerikReporting();
|
||||
app.UseRouting();
|
||||
````
|
||||
|
||||
|
||||
### Add Configuration Settings (Optional)
|
||||
### Adding Connection Strings to the Configuration
|
||||
|
||||
The report generation engine can retrieve Sql Connection Strings and specific Report Generation Engine Settings that provide flexibility of the deployed application. It utilizes the [IConfiguration interface](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration?view=dotnet-plat-ext-6.0) for this purpose.
|
||||
The report generation engine can retrieve SQL Connection Strings and specific Report Generation Engine Settings that provide flexibility of the deployed application. It utilizes the [IConfiguration interface](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration) for this purpose.
|
||||
|
||||
The .NET applications use a [key-value JSON-based](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0) file named by default `appSettings.json`. The default ReportingEngineConfiguration:
|
||||
The .NET applications use a [key-value JSON-based](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) file named by default `appSettings.json`. The default `ReportingEngineConfiguration` will be initialized from `appSettings.json` or `appsettings.{EnvironmentName}.json`.
|
||||
|
||||
````C#
|
||||
ReportingEngineConfiguration = sp.GetService<IConfiguration>()
|
||||
````
|
||||
|
||||
will be initialized from `appSettings.json` or `appsettings.{EnvironmentName}.json`.
|
||||
|
||||
To activate JSON file configuration with a different name, for example, `reportingAppSettings.json`, call the [AddJsonFile](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.jsonconfigurationextensions.addjsonfile?view=dotnet-plat-ext-7.0) extension method on an instance of [ConfigurationBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.configurationbuilder?view=dotnet-plat-ext-7.0).
|
||||
|
||||
In this guide we will create a helper class loading the json-formatted setting:
|
||||
|
||||
````C#
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
static class ConfigurationHelper
|
||||
{
|
||||
public static IConfiguration ResolveConfiguration(IWebHostEnvironment environment)
|
||||
{
|
||||
var reportingConfigFileName = System.IO.Path.Combine(environment.ContentRootPath, "reportingAppSettings.json");
|
||||
return new ConfigurationBuilder()
|
||||
.AddJsonFile(reportingConfigFileName, true)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Finally, all configurations should be placed in the JSON configuraion file (add one in the project root if such does not exist). For example, __ConnectionStrings__ setting should be configured in JSON-based format like this:
|
||||
All Reporting-related configurations should be placed in the JSON configuraion file - (add one in the project root if such does not exist). For example, the `ConnectionStrings` setting should be configured in JSON-based format like this:
|
||||
|
||||
````JSON
|
||||
{
|
||||
//...
|
||||
"ConnectionStrings": {
|
||||
"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true"
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
The above type of connection string lacks information about the data provider and will use *System.Data.SqlClient* as provider invariant name. When it's necessary to specify a different data provider, the following notation is also supported:
|
||||
The above type of connection string lacks information about the data provider and will use [System.Data.SqlClient](https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient) as provider invariant name. When it's necessary to specify a different data provider, the following notation is also supported:
|
||||
|
||||
````JSON
|
||||
{
|
||||
//...
|
||||
"ConnectionStrings": {
|
||||
"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
|
||||
"connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
|
||||
|
@ -158,7 +123,7 @@ The above type of connection string lacks information about the data provider an
|
|||
|
||||
The two types of connection string notations specified above can coexist in a single ConnectionStrings section.
|
||||
|
||||
The last supported type of __ConnectionStrings__ configuration uses an array to provide information about each connection string:
|
||||
The last supported type of `ConnectionStrings` configuration uses an array to provide information about each connection string:
|
||||
|
||||
````JSON
|
||||
{
|
||||
|
@ -173,42 +138,6 @@ The last supported type of __ConnectionStrings__ configuration uses an array to
|
|||
}
|
||||
````
|
||||
|
||||
### Setting up the REST service
|
||||
|
||||
1. Create folder `Controllers`. Right-click on the project name and select __Add > New folder__. Name it `Controllers`.
|
||||
1. Implement a Reports controller. Right-click on the `Controllers` folder and add a new item: __Add > New item > Web API Controller Class__ item. Name it `ReportsController`. This will be our Telerik Reporting REST service in the project.
|
||||
1. Inherit the [ReportsControllerBase](/api/Telerik.Reporting.Services.WebApi.ReportsControllerBase) type and inject the configuration settings in the constructor. This is how a basic implementation of the controller should look like:
|
||||
|
||||
````C#
|
||||
namespace CSharp.Net6.ReportingRestServiceCorsDemo.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using Telerik.Reporting.Services;
|
||||
using Telerik.Reporting.Services.AspNetCore;
|
||||
[Route("api/reports")]
|
||||
public class ReportsController : ReportsControllerBase
|
||||
{
|
||||
public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
|
||||
: base(reportServiceConfiguration)
|
||||
{
|
||||
}
|
||||
protected override HttpStatusCode SendMailMessage(MailMessage mailMessage)
|
||||
{
|
||||
throw new System.NotImplementedException("This method should be implemented in order to send mail messages");
|
||||
//using (var smtpClient = new SmtpClient("smtp01.mycompany.com", 25))
|
||||
//{
|
||||
// smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
// smtpClient.EnableSsl = false;
|
||||
// smtpClient.Send(mailMessage);
|
||||
//}
|
||||
//return HttpStatusCode.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
|
||||
### Test the service implementation
|
||||
|
||||
|
@ -241,4 +170,5 @@ app.UseCors("ReportingRestPolicy");
|
|||
|
||||
## See Also
|
||||
|
||||
* [YouTube video "How to set up a Telerik Reporting REST Service in .NET 5?"](https://www.youtube.com/watch?v=qU_ByzMgJBo)
|
||||
* [ASP.NET Core Web API Implementation Overview]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/asp.net-core-web-api-implementation/overview%})
|
||||
* [Hosting in .NET 6+ with Minimal API]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/asp.net-core-web-api-implementation/how-to-host-reports-service-in-asp.net-core-in-.net-6-with-minimal-api%})
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
---
|
||||
|
||||
title: Hosting in .NET 6+ with Top-Level Statements
|
||||
page_title: Hosting REST Service in ASP.NET Core with Top-Level Statements
|
||||
description: "Learn how to Host Telerik Reporting REST Service in ASP.NET Core in .NET 6 and above with Top-Level Statements in this step by step tutorial."
|
||||
title: Hosting in .NET 6+ with Minimal API
|
||||
page_title: Hosting REST Service in ASP.NET Core with Minimal API
|
||||
description: "Learn how to Host Telerik Reporting REST Service in ASP.NET Core in .NET 6 and above with Minimal API in this step by step tutorial."
|
||||
slug: telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/asp.net-core-web-api-implementation/how-to-host-reports-service-in-asp.net-core-in-.net-6-with-minimal-api
|
||||
tags: how,to,host,reports,service,in,asp.net,core,in,.net,6,with,top-level,statements
|
||||
published: True
|
||||
|
@ -10,10 +9,11 @@ position: 2
|
|||
previous_url: /telerik-reporting-rest-service-net6-minimal-api,/embedding-reports/host-the-report-engine-remotely/telerik-reporting-rest-services/asp.net-core-web-api-implementation/host-reports-service-in-.net-6-with-minimal-api
|
||||
---
|
||||
|
||||
# Hosting the Telerik Reporting REST Service in ASP.NET Core in .NET 6, .NET 7, and .NET 8 with Top-Level Statements
|
||||
# Hosting the Telerik Reporting REST Service in ASP.NET Core in .NET 6+ with Minimal API
|
||||
|
||||
This article guides you how to host a Reports Web Service in order to expose the Reports Generation Engine to an ASP.NET Core in .NET 6 and higher Web Application with Top-Level Statements implementation. Check the [Microsoft Tutorial: Explore ideas using top-level statements to build code as you learn](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements) for general details on the approach.
|
||||
This article guides you how to host a Reporting REST Service in order to expose the Reports Generation Engine to an ASP.NET Core in .NET 6+ Web Application with Minimal APIs.
|
||||
|
||||
Check the [Minimal APIs](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/overview) article for general details on the approach.
|
||||
The guide is separated into sections for readability reasons. Along with the steps, it elaborates on the concepts and theory behind each step.
|
||||
|
||||
## Prerequisites
|
||||
|
@ -53,98 +53,65 @@ In this tutorial, the resulting service will use the sample report definitions d
|
|||
|
||||
> It is recommended to use declarative definitions (TRDP/TRDX/TRBP) authored using the [Standalone Report Designer]({%slug telerikreporting/designing-reports/report-designer-tools/desktop-designers/standalone-report-designer/overview%}) or the [Web Report Designer]({%slug telerikreporting/designing-reports/report-designer-tools/web-report-designer/overview%}) in order to take advantage of their design-time tooling because the VS integrated report designer tooling is still not available in .NET 6+ projects.
|
||||
|
||||
### Add the required dependencies
|
||||
### Add the Required Dependencies
|
||||
|
||||
This guide applies the recommended NuGet package references approach to add the dependencies:
|
||||
|
||||
1. Reference the __Telerik.Reporting.Services.AspNetCore__ (or __Telerik.Reporting.Services.AspNetCore.Trial__) package.
|
||||
1. Optionally, to enable the Office OpenXML document formats (XLSX, DOCX and PPTX) as export options, reference the __Telerik.Reporting.OpenXmlRendering__ (or __Telerik.Reporting.OpenXmlRendering.Trial__) NuGet package.
|
||||
|
||||
> The recommended way of adding the necessary dependencies is to use the [Progress Telerik proprietary NuGet feed]({%slug telerikreporting/using-reports-in-applications/how-to-add-the-telerik-private-nuget-feed-to-visual-studio%}) and reference the dependencies as NuGet packages. This would also add the indirect dependencies to your project bringing easier dependency management. Alternatively, the assemblies are available in the `\Bin\net6.0\` and `\Bin\netstandard2.0\` folders of Telerik Reporting installation directory. However, this would require to manually add all indirect dependencies listed in [.NET Support - Requirements]({%slug telerikreporting/using-reports-in-applications/dot-net-core-support%}#requirements) section and also the following dependency package: [Microsoft.AspNetCore.Mvc.NewtonsoftJson version 5.0.0](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson/) and [DocumentFormat.OpenXML version 2.7.2.0 or above](https://www.nuget.org/packages/DocumentFormat.OpenXml/). Note that you need the last reference only to enable the Office OpenXML document formats. The Reporting engine relies on the GDI+ API which is available on the Windows OS. On Linux and macOS we use library called [libgdiplus](https://www.mono-project.com/docs/gui/libgdiplus/) instead. The GDI+ API is required for measuring, laying out, rendering the text glyphs and images.
|
||||
> The recommended way of adding the necessary dependencies is to use the [Progress Telerik proprietary NuGet feed]({%slug telerikreporting/using-reports-in-applications/how-to-add-the-telerik-private-nuget-feed-to-visual-studio%}) and reference the dependencies as NuGet packages. This would also add the indirect dependencies to your project bringing easier dependency management.
|
||||
Alternatively, the assemblies are available in the `\Bin\net6.0\` and `\Bin\netstandard2.0\` folders of Telerik Reporting installation directory. However, this would require to manually add all indirect dependencies listed in [.NET Support - Requirements]({%slug telerikreporting/using-reports-in-applications/dot-net-core-support%}#requirements) section and also the following dependency package: [Microsoft.AspNetCore.Mvc.NewtonsoftJson version 5.0.0](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson/) and [DocumentFormat.OpenXML version 2.7.2.0 or above](https://www.nuget.org/packages/DocumentFormat.OpenXml/).
|
||||
Note that you need the last reference only to enable the Office OpenXML document formats. The Reporting engine relies on the [GDI+ API](https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-gdi-start) which is available on the Windows OS. On Linux and macOS we use the [SkiaSharp](https://github.com/mono/SkiaSharp) 2D Graphics Library based on Google's [Skia](https://skia.org/) Graphics Library.
|
||||
|
||||
### Setup the Program.cs file as a starting point of your Reporting REST Service project with Top-Level Statements
|
||||
### Setup the Program.cs file as a starting point of the Reporting REST Service project with Minimal APIs
|
||||
|
||||
Modify the `Program.cs` file in the project to enable the Reports Service functionality.
|
||||
|
||||
1. Make sure the application is configured for WebAPI controllers and call the `AddNewtonsoftJson` on the IMvcBuilder object to place the NewtonsoftJson serialization:
|
||||
1. Call the [`AddNewtonsoftJson`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.newtonsoftjsonmvcbuilderextensions.addnewtonsoftjson) extension method on the [IMvcBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.imvcbuilder) object to enable the **NewtonsoftJson** serialization:
|
||||
|
||||
````CSharp
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
builder.Services.AddNewtonsoftJson();
|
||||
````
|
||||
|
||||
|
||||
1. Add the dedicated configuration object needed from the Reports Service in the dependency container. Note how the report source resolver will target the Reports folder we created earlier.
|
||||
1. Set up the [ReportServiceConfiguration](/api/telerik.reporting.services.reportserviceconfiguration) by invoking the `AddTelerikReporting` extension method on the [IMvcBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.imvcbuilder) object. In the code below, the first argument will represent the [HostAppId](/api/telerik.reporting.services.reportserviceconfiguration#Telerik_Reporting_Services_ReportServiceConfiguration_HostAppId) of the [ReportServiceConfiguration](/api/telerik.reporting.services.reportserviceconfiguration) object, while the second is the path that will be passed to the [UriReportSourceResolver](/api/telerik.reporting.services.urireportsourceresolver).
|
||||
|
||||
````CSharp
|
||||
// Configure dependencies for ReportsController.
|
||||
builder.Services.TryAddSingleton<IReportServiceConfiguration>(sp =>
|
||||
new ReportServiceConfiguration
|
||||
{
|
||||
// The default ReportingEngineConfiguration will be initialized from appsettings.json or appsettings.{EnvironmentName}.json:
|
||||
ReportingEngineConfiguration = sp.GetService<IConfiguration>(),
|
||||
// In case the ReportingEngineConfiguration needs to be loaded from a specific configuration file, use the approach below:
|
||||
//ReportingEngineConfiguration = ResolveSpecificReportingConfiguration(sp.GetService<IWebHostEnvironment>()),
|
||||
HostAppId = "ReportingNet6",
|
||||
Storage = new FileStorage(),
|
||||
ReportSourceResolver = new UriReportSourceResolver(System.IO.Path.Combine(sp.GetService<IWebHostEnvironment>().ContentRootPath, "Reports"))
|
||||
});
|
||||
var reportsPath = Path.Combine(builder.Environment.ContentRootPath, "Reports");
|
||||
|
||||
builder.Services.AddTelerikReporting("ReportingNet", reportsPath);
|
||||
````
|
||||
|
||||
|
||||
1. Make sure the endpoints are configured for API controllers by adding the following line in the lambda expression argument after the *UseRouting();* call:
|
||||
1. Register the Telerik Reportig Minimal API by invoking the `UseTelerikReporting` extension method on the [WebApplication](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.webapplication) object. The application must also enable the endpoint routing middleware added by the [UseRouting](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.endpointroutingapplicationbuilderextensions.userouting) method:
|
||||
|
||||
````CSharp
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
//...
|
||||
});
|
||||
app.UseTelerikReporting();
|
||||
app.UseRouting();
|
||||
````
|
||||
|
||||
|
||||
### Add Configuration Settings to the Program.cs file (Optional)
|
||||
### Adding Connection Strings to the Configuration
|
||||
|
||||
The report generation engine can retrieve SQL Connection Strings and specific Report Generation Engine Settings that provide flexibility of the deployed application. It utilizes the [IConfiguration interface](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration?view=dotnet-plat-ext-6.0) for this purpose.
|
||||
The report generation engine can retrieve SQL Connection Strings and specific Report Generation Engine Settings that provide flexibility of the deployed application. It utilizes the [IConfiguration interface](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration) for this purpose.
|
||||
|
||||
The .NET applications use a [key-value JSON-based](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-5.0) file named by default `appSettings.json`. The default ReportingEngineConfiguration:
|
||||
The .NET applications use a [key-value JSON-based](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/) file named by default `appSettings.json`. The default `ReportingEngineConfiguration` will be initialized from `appSettings.json` or `appsettings.{EnvironmentName}.json`.
|
||||
|
||||
````CSharp
|
||||
ReportingEngineConfiguration = sp.GetService<IConfiguration>();
|
||||
````
|
||||
|
||||
will be initialized from `appSettings.json` or `appsettings.{EnvironmentName}.json`.
|
||||
|
||||
To activate JSON file configuration with a different name, for example, `reportingAppSettings.json`, call the [AddJsonFile](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.jsonconfigurationextensions.addjsonfile?view=dotnet-plat-ext-7.0) extension method on an instance of [ConfigurationBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.configurationbuilder?view=dotnet-plat-ext-7.0).
|
||||
|
||||
In this guide we will create a helper method loading the json-formatted setting:
|
||||
|
||||
````CSharp
|
||||
static IConfiguration ResolveSpecificReportingConfiguration(IWebHostEnvironment environment)
|
||||
{
|
||||
// If a specific configuration needs to be passed to the reporting engine, add it through a new IConfiguration instance.
|
||||
var reportingConfigFileName = System.IO.Path.Combine(environment.ContentRootPath, "reportingAppSettings.json");
|
||||
return new ConfigurationBuilder()
|
||||
.AddJsonFile(reportingConfigFileName, true)
|
||||
.Build();
|
||||
}
|
||||
````
|
||||
|
||||
Finally, all configurations should be placed in the JSON configuraion file (add one in the project root if such does not exist). For example, __ConnectionStrings__ setting should be configured in JSON-based format like this:
|
||||
All Reporting-related configurations should be placed in the JSON configuraion file - (add one in the project root if such does not exist). For example, the `ConnectionStrings` setting should be configured in JSON-based format like this:
|
||||
|
||||
````JSON
|
||||
{
|
||||
//...
|
||||
"ConnectionStrings": {
|
||||
"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true"
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
The above type of connection string lacks information about the data provider and will use *System.Data.SqlClient* as provider invariant name. When it's necessary to specify a different data provider, the following notation is also supported:
|
||||
The above type of connection string lacks information about the data provider and will use [System.Data.SqlClient](https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient) as provider invariant name. When it's necessary to specify a different data provider, the following notation is also supported:
|
||||
|
||||
````JSON
|
||||
{
|
||||
//...
|
||||
"ConnectionStrings": {
|
||||
"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
|
||||
"connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
|
||||
|
@ -156,7 +123,7 @@ The above type of connection string lacks information about the data provider an
|
|||
|
||||
The two types of connection string notations specified above can coexist in a single ConnectionStrings section.
|
||||
|
||||
The last supported type of __ConnectionStrings__ configuration uses an array to provide information about each connection string:
|
||||
The last supported type of `ConnectionStrings` configuration uses an array to provide information about each connection string:
|
||||
|
||||
````JSON
|
||||
{
|
||||
|
@ -171,56 +138,18 @@ The last supported type of __ConnectionStrings__ configuration uses an array to
|
|||
}
|
||||
````
|
||||
|
||||
### Setting up the REST service
|
||||
|
||||
1. Create folder `Controllers`. Right-click on the project name and select __Add__ > __New folder__. Name it `Controllers`.
|
||||
1. Implement a Reports controller. Right-click on the `Controllers` folder and add a new item: __Add__ > __New item__ > __API Controller - Empty__ item. Name it `ReportsController`. This will be our Telerik Reporting REST service in the project.
|
||||
1. Inherit the [ReportsControllerBase](/api/Telerik.Reporting.Services.WebApi.ReportsControllerBase) type and inject the configuration settings in the constructor. This is how a basic implementation of the controller should look like:
|
||||
### Test the Service Implementation
|
||||
|
||||
````CSharp
|
||||
namespace TopLevelStatements.Controllers
|
||||
{
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Telerik.Reporting.Services;
|
||||
using Telerik.Reporting.Services.AspNetCore;
|
||||
To ensure that the service operates, run the application and navigate to either of the General REST Service API URLs `{applicationRoot}/api/reports/formats` or `{applicationRoot}/api/reports/version`.
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ReportsController : ReportsControllerBase
|
||||
{
|
||||
public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
|
||||
: base(reportServiceConfiguration)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HttpStatusCode SendMailMessage(MailMessage mailMessage)
|
||||
{
|
||||
throw new System.NotImplementedException("This method should be implemented in order to send mail messages");
|
||||
|
||||
// using (var smtpClient = new SmtpClient("smtp01.mycompany.com", 25))
|
||||
// {
|
||||
// smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
// smtpClient.EnableSsl = false;
|
||||
// smtpClient.Send(mailMessage);
|
||||
// }
|
||||
// return HttpStatusCode.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
|
||||
### Test the service implementation
|
||||
|
||||
To ensure that the service operates, run the application and navigate to either of the General REST Service API URLs `{applicationRoot}/api/reports/formats` or `{applicationRoot}/api/reports/version`. The first should return a [JSON representing the supported rendering extensions]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/rest-api-reference/general-api/get-available-document-formats%}), and the second - the [version of the Reporting REST Service]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/rest-api-reference/general-api/get-version%}).
|
||||
The first should return a [JSON representing the supported rendering extensions]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/rest-api-reference/general-api/get-available-document-formats%}), and the second - the [version of the Reporting REST Service]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/rest-api-reference/general-api/get-version%}).
|
||||
|
||||
### Enable Cross-Origin Resource Sharing (CORS) (Optional)
|
||||
|
||||
You may need to enable [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), for example, if you use the REST Service from clients hosted in different domains.
|
||||
You may need to enable [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), for example, if the Reporting REST Service is used from clients hosted in different domains.
|
||||
|
||||
Add the following service to the *Program.cs* file to add a new CORS policy for the REST Service:
|
||||
Add the following service to the **Program.cs** file to add a new CORS policy for the REST Service:
|
||||
|
||||
````CSharp
|
||||
builder.Services.AddCors(corsOption => corsOption.AddPolicy(
|
||||
|
@ -234,7 +163,7 @@ builder.Services.AddCors(corsOption => corsOption.AddPolicy(
|
|||
));
|
||||
````
|
||||
|
||||
Activate the above policy for the application by adding the code below in the application configuration part of the `Program.cs` file:
|
||||
Activate the above policy for the application by adding the code below in the application configuration part of the **Program.cs** file:
|
||||
|
||||
````CSharp
|
||||
app.UseCors("ReportingRestPolicy");
|
||||
|
@ -244,4 +173,4 @@ app.UseCors("ReportingRestPolicy");
|
|||
|
||||
A full example can be found in the installation folder of Telerik Reporting:
|
||||
|
||||
`C:\Program Files (x86)\Progress\Telerik Reporting {{site.suiteversion}}\Examples\CSharp\.NET 6\ReportingRestServiceCorsDemo\CSharp.Net6.ReportingRestServiceCorsDemo`
|
||||
`C:\Program Files (x86)\Progress\Telerik Reporting {{site.suiteversion}}\Examples\CSharp\.NET 6\ReportingRestServiceCorsDemo\CSharp.Net8.ReportingRestServiceCorsDemo`
|
||||
|
|
|
@ -0,0 +1,247 @@
|
|||
---
|
||||
|
||||
title: Hosting in .NET 6+ with Controllers
|
||||
page_title: Hosting REST Service in ASP.NET Core with Controllers
|
||||
description: "Learn how to Host Telerik Reporting REST Service in ASP.NET Core in .NET 6 and above with Top-Level Statements and controller-based APIs in this step by step tutorial."
|
||||
slug: telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/asp.net-core-web-api-implementation/host-reports-service-in-.net-with-controllers
|
||||
tags: how,to,host,reports,service,in,asp.net,core,in,.net,6,with,top-level,statements,and,controllers
|
||||
published: True
|
||||
position: 3
|
||||
---
|
||||
|
||||
# Hosting the Telerik Reporting REST Service in ASP.NET Core in .NET 6 and .NET 8 with Top-Level Statements
|
||||
|
||||
This article guides you how to host a Reports Web Service in order to expose the Reports Generation Engine to an ASP.NET Core in .NET 6 and higher Web Application with Top-Level Statements implementation. Check the [Microsoft Tutorial: Explore ideas using top-level statements to build code as you learn](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements) for general details on the approach.
|
||||
|
||||
The guide is separated into sections for readability reasons. Along with the steps, it elaborates on the concepts and theory behind each step.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* [Visual Studio 2022, version 17+](https://www.visualstudio.com/vs/)
|
||||
* [NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0) or higher
|
||||
|
||||
## Using the REST Service Project Template
|
||||
|
||||
In Visual Studio open the __Add New Project__ dialog and select *Telerik Reporting REST Service* project template. After clicking `Create` a menu pops up that allows you to configure the following properties of the REST Service: target framework, service clients (report viewer and report designer), Cross-Origin Resource Sharing, Host Application ID, and Application URL.
|
||||
|
||||
![REST Service Project Configuration page from the Visual Studio project template for adding Telerik Reporting REST Service](images/rest-service-project-configuration-menu-net6.png)
|
||||
|
||||
Set the Target Framework to .NET 6, .NET 8 or .NET 9.
|
||||
|
||||
Once you have configured the rest of the options to your liking, click `Finish` and a new project, containing all the necessary files and packages to host the Telerik Reporting REST service instance, will be added to your solution.
|
||||
|
||||
## Manually configuring the Telerik.Reporting REST Service
|
||||
|
||||
### Creating a Sample ASP.NET Core in .NET 6+ Project
|
||||
|
||||
First, you need to create a new ASP.NET Core project:
|
||||
|
||||
1. Open __Visual Studio 2022__.
|
||||
1. From the __File__ menu, select __New__ > __Project__.
|
||||
1. In the __Create a new project__ dialog select __ASP.NET Core Web App__ project template and click __Next__.
|
||||
1. In the __Configure your new project__ dialog choose a name and location for the project and click __Next__.
|
||||
1. In the __Additional information__ dialog select from the drop down __.NET 6.0 (Long-term support)__ or .NET 8. If you configure the project for HTTPS make sure to have a proper certificate assigned. Click on __Create__.
|
||||
|
||||
### Add Report Definitions
|
||||
|
||||
In this tutorial, the resulting service will use the sample report definitions deployed with the Telerik Reporting product installer:
|
||||
|
||||
1. Find the sample reports in *{Telerik Reporting installation path}\Report Designer\Examples*.
|
||||
1. Add a new folder to your solution called `Reports` and copy all sample reports into it.
|
||||
1. Later in the tutorial we will make sure that the ReportsController is able to resolve the definitions for the requested reports from this project folder.
|
||||
|
||||
> It is recommended to use declarative definitions (TRDP/TRDX/TRBP) authored using the [Standalone Report Designer]({%slug telerikreporting/designing-reports/report-designer-tools/desktop-designers/standalone-report-designer/overview%}) or the [Web Report Designer]({%slug telerikreporting/designing-reports/report-designer-tools/web-report-designer/overview%}) in order to take advantage of their design-time tooling because the VS integrated report designer tooling is still not available in .NET 6+ projects.
|
||||
|
||||
### Add the Required Dependencies
|
||||
|
||||
This guide applies the recommended NuGet package references approach to add the dependencies:
|
||||
|
||||
1. Reference the __Telerik.Reporting.Services.AspNetCore__ (or __Telerik.Reporting.Services.AspNetCore.Trial__) package.
|
||||
1. Optionally, to enable the Office OpenXML document formats (XLSX, DOCX and PPTX) as export options, reference the __Telerik.Reporting.OpenXmlRendering__ (or __Telerik.Reporting.OpenXmlRendering.Trial__) NuGet package.
|
||||
|
||||
> The recommended way of adding the necessary dependencies is to use the [Progress Telerik proprietary NuGet feed]({%slug telerikreporting/using-reports-in-applications/how-to-add-the-telerik-private-nuget-feed-to-visual-studio%}) and reference the dependencies as NuGet packages. This would also add the indirect dependencies to your project bringing easier dependency management.
|
||||
Alternatively, the assemblies are available in the `\Bin\net6.0\` and `\Bin\netstandard2.0\` folders of Telerik Reporting installation directory. However, this would require to manually add all indirect dependencies listed in [.NET Support - Requirements]({%slug telerikreporting/using-reports-in-applications/dot-net-core-support%}#requirements) section and also the following dependency package: [Microsoft.AspNetCore.Mvc.NewtonsoftJson version 5.0.0](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson/) and [DocumentFormat.OpenXML version 2.7.2.0 or above](https://www.nuget.org/packages/DocumentFormat.OpenXml/).
|
||||
Note that you need the last reference only to enable the Office OpenXML document formats. The Reporting engine relies on the [GDI+ API](https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-gdi-start) which is available on the Windows OS. On Linux and macOS we use the [SkiaSharp](https://github.com/mono/SkiaSharp) 2D Graphics Library based on Google's [Skia](https://skia.org/) Graphics Library.
|
||||
|
||||
### Setup the Program.cs file as a starting point of the Reporting REST Service Project with Top-Level Statements
|
||||
|
||||
Modify the `Program.cs` file in the project to enable the Reports Service functionality.
|
||||
|
||||
1. Make sure the application is configured for WebAPI controllers using the [AddControllers()](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.mvcservicecollectionextensions.addcontrollers) extension method and call the [AddNewtonsoftJson](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.newtonsoftjsonmvcbuilderextensions.addnewtonsoftjson) extension method on the [IMvcBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.imvcbuilder) object to enable the **NewtonsoftJson** serialization:
|
||||
|
||||
````CSharp
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
````
|
||||
|
||||
|
||||
1. Add the dedicated [ReportServiceConfiguration](/api/telerik.reporting.services.reportserviceconfiguration) object needed from the Reports Service in the dependency container. Note how the report source resolver will target the `Reports` folder we created earlier.
|
||||
|
||||
````CSharp
|
||||
// Configure dependencies for ReportsController.
|
||||
builder.Services.TryAddSingleton<IReportServiceConfiguration>(sp =>
|
||||
new ReportServiceConfiguration
|
||||
{
|
||||
// The default ReportingEngineConfiguration will be initialized from appsettings.json or appsettings.{EnvironmentName}.json:
|
||||
ReportingEngineConfiguration = sp.GetService<IConfiguration>(),
|
||||
// In case the ReportingEngineConfiguration needs to be loaded from a specific configuration file, use the approach below:
|
||||
//ReportingEngineConfiguration = ResolveSpecificReportingConfiguration(sp.GetService<IWebHostEnvironment>()),
|
||||
HostAppId = "ReportingNet6",
|
||||
Storage = new FileStorage(),
|
||||
ReportSourceResolver = new UriReportSourceResolver(System.IO.Path.Combine(sp.GetService<IWebHostEnvironment>().ContentRootPath, "Reports"))
|
||||
});
|
||||
````
|
||||
|
||||
|
||||
1. Make sure the endpoints are configured for API controllers by adding the following line in the lambda expression argument after the [UseRouting](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.endpointroutingapplicationbuilderextensions.userouting) call:
|
||||
|
||||
````CSharp
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
//...
|
||||
});
|
||||
````
|
||||
|
||||
|
||||
### Add Configuration Settings to the Program.cs file (Optional)
|
||||
|
||||
The report generation engine can retrieve SQL Connection Strings and specific Report Generation Engine Settings that provide flexibility of the deployed application. It utilizes the [IConfiguration interface](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration?view=dotnet-plat-ext-6.0) for this purpose.
|
||||
|
||||
The .NET applications use a [key-value JSON-based](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-5.0) file named by default `appSettings.json`. The default ReportingEngineConfiguration:
|
||||
|
||||
````CSharp
|
||||
ReportingEngineConfiguration = sp.GetService<IConfiguration>();
|
||||
````
|
||||
|
||||
will be initialized from `appSettings.json` or `appsettings.{EnvironmentName}.json`.
|
||||
|
||||
To activate JSON file configuration with a different name, for example, `reportingAppSettings.json`, call the [AddJsonFile](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.jsonconfigurationextensions.addjsonfile?view=dotnet-plat-ext-7.0) extension method on an instance of [ConfigurationBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.configurationbuilder?view=dotnet-plat-ext-7.0).
|
||||
|
||||
In this guide we will create a helper method loading the json-formatted setting:
|
||||
|
||||
````CSharp
|
||||
static IConfiguration ResolveSpecificReportingConfiguration(IWebHostEnvironment environment)
|
||||
{
|
||||
// If a specific configuration needs to be passed to the reporting engine, add it through a new IConfiguration instance.
|
||||
var reportingConfigFileName = System.IO.Path.Combine(environment.ContentRootPath, "reportingAppSettings.json");
|
||||
return new ConfigurationBuilder()
|
||||
.AddJsonFile(reportingConfigFileName, true)
|
||||
.Build();
|
||||
}
|
||||
````
|
||||
|
||||
Finally, all configurations should be placed in the JSON configuraion file (add one in the project root if such does not exist). For example, __ConnectionStrings__ setting should be configured in JSON-based format like this:
|
||||
|
||||
````JSON
|
||||
{
|
||||
//...
|
||||
"ConnectionStrings": {
|
||||
"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true"
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
The above type of connection string lacks information about the data provider and will use *System.Data.SqlClient* as provider invariant name. When it's necessary to specify a different data provider, the following notation is also supported:
|
||||
|
||||
````JSON
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
|
||||
"connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
|
||||
"providerName": "System.Data.SqlClient"
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
The two types of connection string notations specified above can coexist in a single `ConnectionStrings` section.
|
||||
|
||||
The last supported type of __ConnectionStrings__ configuration uses an array to provide information about each connection string:
|
||||
|
||||
````JSON
|
||||
{
|
||||
//...
|
||||
"ConnectionStrings": [
|
||||
{
|
||||
"name": "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString",
|
||||
"connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
|
||||
"providerName": "System.Data.SqlClient"
|
||||
}
|
||||
]
|
||||
}
|
||||
````
|
||||
|
||||
### Setting up the Reporting REST service
|
||||
|
||||
1. Create folder `Controllers`. Right-click on the project name and select __Add__ > __New folder__. Name it `Controllers`.
|
||||
1. Implement a Reports controller. Right-click on the `Controllers` folder and add a new item: __Add__ > __New item__ > __API Controller - Empty__ item. Name it `ReportsController`. This will be our Telerik Reporting REST service in the project.
|
||||
1. Inherit the [ReportsControllerBase](/api/Telerik.Reporting.Services.WebApi.ReportsControllerBase) type and inject the configuration settings in the constructor. This is how a basic implementation of the controller should look like:
|
||||
|
||||
````CSharp
|
||||
namespace TopLevelStatements.Controllers
|
||||
{
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Telerik.Reporting.Services;
|
||||
using Telerik.Reporting.Services.AspNetCore;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ReportsController : ReportsControllerBase
|
||||
{
|
||||
public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
|
||||
: base(reportServiceConfiguration)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HttpStatusCode SendMailMessage(MailMessage mailMessage)
|
||||
{
|
||||
throw new System.NotImplementedException("This method should be implemented in order to send mail messages");
|
||||
|
||||
// using (var smtpClient = new SmtpClient("smtp01.mycompany.com", 25))
|
||||
// {
|
||||
// smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
// smtpClient.EnableSsl = false;
|
||||
// smtpClient.Send(mailMessage);
|
||||
// }
|
||||
// return HttpStatusCode.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
|
||||
### Test the service implementation
|
||||
|
||||
To ensure that the service operates, run the application and navigate to either of the General REST Service API URLs `{applicationRoot}/api/reports/formats` or `{applicationRoot}/api/reports/version`. The first should return a [JSON representing the supported rendering extensions]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/rest-api-reference/general-api/get-available-document-formats%}), and the second - the [version of the Reporting REST Service]({%slug telerikreporting/using-reports-in-applications/host-the-report-engine-remotely/telerik-reporting-rest-services/rest-api-reference/general-api/get-version%}).
|
||||
|
||||
### Enable Cross-Origin Resource Sharing (CORS) (Optional)
|
||||
|
||||
You may need to enable [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), for example, if you use the REST Service from clients hosted in different domains.
|
||||
|
||||
Add the following service to the *Program.cs* file to add a new CORS policy for the REST Service:
|
||||
|
||||
````CSharp
|
||||
builder.Services.AddCors(corsOption => corsOption.AddPolicy(
|
||||
"ReportingRestPolicy",
|
||||
corsBuilder =>
|
||||
{
|
||||
corsBuilder.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
}
|
||||
));
|
||||
````
|
||||
|
||||
Activate the above policy for the application by adding the code below in the application configuration part of the `Program.cs` file:
|
||||
|
||||
````CSharp
|
||||
app.UseCors("ReportingRestPolicy");
|
||||
````
|
||||
|
||||
## Demo project
|
||||
|
||||
A full example can be found in the installation folder of Telerik Reporting:
|
||||
|
||||
`C:\Program Files (x86)\Progress\Telerik Reporting {{site.suiteversion}}\Examples\CSharp\.NET 6\ReportingRestServiceCorsDemo\CSharp.Net6.ReportingRestServiceCorsDemo`
|
|
@ -35,6 +35,11 @@ The Telerik Reporting REST Web API service is represented by the abstract [Repor
|
|||
|
||||
{{source=CodeSnippets\MvcCS\Controllers\ReportsController.cs region=ReportsControllerImplementation}}
|
||||
{{source=CodeSnippets\MvcVB\Controllers\ReportsController.vb region=ReportsControllerImplementation}}
|
||||
|
||||
>note Starting with the [2024 Q4 (18.3.24.1112)](https://www.telerik.com/support/whats-new/reporting/release-history/progress-telerik-reporting-2024-q4-(18-3-24-1112)), it is possible to define the [ReportServiceConfiguration](/api/Telerik.Reporting.Services.WebApi.ReportsControllerBase#Telerik_Reporting_Services_WebApi_ReportsControllerBase_ReportServiceConfiguration) with less code using the `AddTelerikReporting` extension method:
|
||||
|
||||
{{source=CodeSnippets\MvcCS\Controllers\ReportsController.cs region=ReportsControllerImplementationMinimal}}
|
||||
{{source=CodeSnippets\MvcVB\Controllers\ReportsController.vb region=ReportsControllerImplementationMinimal}}
|
||||
|
||||
[ReportsControllerBase](/api/Telerik.Reporting.Services.WebApi.ReportsControllerBase) inherits [System.Web.Http.ApiController](https://learn.microsoft.com/en-us/dotnet/api/system.web.http.apicontroller?view=aspnet-webapi-5.2) and implements all necessary API actions. The provided sample implementation will resolve.trdx|.trdp report definitions from the Reports subfolder of the hosting ASP.NET application root. Other 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) from the service clients.
|
||||
|
||||
|
|
|
@ -48,6 +48,17 @@ For more detailed information, refer to the following articles:
|
|||
|
||||
The Report item exposes a set of properties that allow you to control some aspects of its processing and rendering.
|
||||
|
||||
* `AutoRun`— As of [2024 Q4 (18.3.24.1112)](https://www.telerik.com/support/whats-new/reporting/release-history/progress-telerik-reporting-2024-q4-(18-3-24-1112)), it is possible to have control over the automatically initiated rendering process by using the [`AutoRun`](/api/Telerik.Reporting.Report.html#Telerik_Reporting_Report_AutoRun) property. By default, `AutoRun` is `True`.
|
||||
|
||||
When `AutoRun=True`, the report loading behavior does not change: the report is automatically loaded if all parameters have valid values, or waits until all parameter values are valid.
|
||||
|
||||
When `AutoRun=False`:
|
||||
|
||||
- The Report Viewer displays the **Preview** button in the Parameters Area even if all [Report Parameters]({%slug telerikreporting/designing-reports/connecting-to-data/report-parameters/overview%}) have [`AutoRefresh`](/api/telerik.reporting.reportparameter#Telerik_Reporting_ReportParameter_AutoRefresh)`=True`.
|
||||
- If all [Report Parameters]({%slug telerikreporting/designing-reports/connecting-to-data/report-parameters/overview%}) have valid values, the Report Viewer does not trigger report rendering and displays prompt message in the Report Area to the end user with information on how they may trigger the rendering(*by clicking on the Preview button*).
|
||||
|
||||
>note Currently, the [`AutoRun`](/api/Telerik.Reporting.Report.html#Telerik_Reporting_Report_AutoRun) functionality is not supported in the [Native Blazor]({%slug telerikreporting/embedding-reports/display-reports-in-applications/web-application/native-blazor-report-viewer/overview%}) and [Native Angular]({%slug telerikreporting/using-reports-in-applications/display-reports-in-applications/web-application/native-angular-report-viewer/overview%}) Report Viewers.
|
||||
|
||||
* `SkipBlankPages`— As of [R1 2021 SP1 (15.0.21.224)](https://www.telerik.com/support/whats-new/reporting/release-history/progress-telerik-reporting-r1-2021-sp1-15-0-21-224), you can indicate to the Reporting engine whether to ignore the pages with non-significant content by using the [`SkipBlankPages`](/api/Telerik.Reporting.Report.html#Telerik_Reporting_Report_SkipBlankPages) property. By default, `SkipBlankPages` is `True`.
|
||||
|
||||
For example, `SkipBlankPages` may be kept `True` to remove the empty pages due to horizontal page breaks. For more information, refer to the articles on [horizontal paging]({%slug telerikreporting/designing-reports/rendering-and-paging/understanding-pagination%}#horizontal-paging) and on [skipping blank pages in the rendered report]({%slug telerikreporting/designing-reports/rendering-and-paging/understanding-rendering-behaviors%}#skip-blank-pages-in-the-rendered-report).
|
||||
|
|
Загрузка…
Ссылка в новой задаче