Custom Report Source Resolver API not working

1 Answer 62 Views
Report Viewer - ASP.NET Report Viewer - HTML5 Report Viewer - MVC
Lasitha
Top achievements
Rank 1
Iron
Lasitha asked on 02 Mar 2023, 09:56 AM

I'm trying to implement the REST Custom Report Source Resolver in a .net core web api. But the reports are not showing even the URL is not working. I have used a middleware to connect this to the application. Bellow you can see the regarding. cods.

 

middleware class

public class TelerikReportingMiddleware
    {
        private readonly RequestDelegate _next;

        public TelerikReportingMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext context, IAPIService aPIService)
        {
            string[] path = !string.IsNullOrEmpty(context.Request.Path.Value) ? context.Request.Path.Value.Split("/") : new string[4];

            if (path.Length > 2 && path[2] != null && path[2].Equals("telerikreports", StringComparison.CurrentCultureIgnoreCase))
            {
                if (context.Request.RouteValues["controller"] == null)
                {
                    context.Request.RouteValues["controller"] = path[2];
                }
                if (context.Request.RouteValues["action"] == null)
                {
                    context.Request.RouteValues["action"] = path[3];
                }

                if (!context.Request.Headers.ContainsKey("IntegrationID"))
                {
                    var appId = "1";
                    context.Request.Headers.Add("IntegrationID", appId);
                }
            }

            await _next(context);
        }

        private async Task ReturnErrorResponse(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            await context.Response.WriteAsJsonAsync("Bad Request: Integration Not Defined, " +
                "Request ID Sould be defined in the Header section of the request");
        }
    }

 

Report Resolver class

 

public class BLReportResolver : IReportResolver
    {
        private readonly string _serverPath;

        public BLReportResolver()
        {
            _serverPath = Path.Combine(Directory.GetCurrentDirectory(), "TelerikReports");
        }

        public ReportSource Resolve(string reportId)
        {
            try
            {
                /* get path to report */
                var sourceReportSource = new UriReportSource { Uri = Path.Combine(_serverPath, reportId) };

                //retrieve an instance of the report     
                var reportPackager = new ReportPackager();
                using (var sourceStream = File.OpenRead(sourceReportSource.Uri))
                {
                    var report = (Report)reportPackager.UnpackageDocument(sourceStream);

                    var reportInstance = new InstanceReportSource
                    {
                        ReportDocument = report
                    };

                    return new InstanceReportSource { ReportDocument = reportInstance.ReportDocument };
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return null;
            }
        }
    }

 

controller class

 

[Route("api/[controller]")]
    [ApiController]
    public class TelerikReportsController : ReportsControllerBase
    {

        static readonly ReportServiceConfiguration configurationInstance =
            new ReportServiceConfiguration
            {
                HostAppId = "TelerikRESTReports",
                Storage = new FileStorage(),
                ReportResolver = new BLReportResolver(),
                ReportSourceResolver = new UriReportSourceResolver(Path.GetFullPath("~/TelerikReports"))
            };

        public TelerikReportsController()
        {
            this.ReportServiceConfiguration = configurationInstance;

        }
    }

 

what can be the issue?

        

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 06 Mar 2023, 01:26 PM

Hi Lasitha,

Thank you for the provided code!

The most likely problem is that you have implemented the deprecated IReportResolver interface, please implement the IReportSourceResolver interface instead and try again.

The How to use Custom Report Source Resolver and Custom Report Document Resolver - Telerik Reporting article should give you some directions on how to implement the interface.

After the custom IReportSourceResolver is created, you should set it to the ReportServiceConfiguration.ReportSourceResolver property.

Please give this approach a go and let me know if that helps resolve the problem.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
Report Viewer - ASP.NET Report Viewer - HTML5 Report Viewer - MVC
Asked by
Lasitha
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Share this question
or