Steps for Implementing a Custom ReportSource Resolver
This article explains how to create a custom report source resolver for the Telerik Reporting REST service. In this example, the resolver's purpose will be to return a XmlReportSource with an XML report definition obtained from an SQL Server database.
-
Create a class which implements the IReportSourceResolver interface. Its Resolve method will be called whenever the engine needs to create a ReportSource instance based on the parameter named report. The value of the report parameter will be initialized with the value of the Report property of the report viewer's ReportSource object.
-
Find the
ReportSourceResolver
property of the ReportServiceConfiguration, and set it to an instance of the custom report source resolver or to a chain of resolver instances including the custom one:-
In
.NET Framework
the property is in the implementation of the ReportsControllerBase class -
In
.NET
and.NET Core
theReportServiceConfiguration
is usually added as a Singleton in the DI Container in the starting point of the application:
-
-
Request the report from the HTML5 Report Viewer on the client:
-
To create the database use the following script:
To enter some data into the database you can manually edit the Reports table. XML report definitions can be obtained from the sample .trdx report files installed together with the product and are located in [Telerik_Reporting_Install_Dir]\Report Designer\Examples. In newer versions, all sample reports of the Standalone Report Designer are in TRDP format. You can use the Standalone Report Designer - File - Save As option to convert them to TRDX files.
How to implement and use custom IReportSourceResolver with fallback mechanism:
-
Add to your IReportSourceResolver implementation a constructor with the parameter IReportSourceResolver parentResolver. Then use the parentResolver if the custom report source resolving mechanism fails.
-
Add to the
ReportServiceConfiguration
theIReportSourceResolver
implementations in a chain. Thus the custom one will be executed first, if it fails the second one, and so on.-
In
.NET Framework
theReportServiceConfiguration
is configured in the implementation of the ReportsControllerBase class -
In
.NET
and.NET Core
theReportServiceConfiguration
is usually added as a Singleton in the DI Container at the starting point of the application:
You can use for fallback the default IReportSourceResolver implementations:
- TypeReportSourceResolver - Resolves IReportDocument from Assembly Qualified Name of a Report or ReportBook class
- UriReportSourceResolver - Resolves IReportDocument from the physical path to
TRDP
,TRDX
orTRBP
file
-