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?