Integrating jsreport.local and jsreport.client in Web API 2.0
-
Hello,
We currently have jsreport running successfully in a Web API. However it is extremely slow when rendering, much more so than directly from the report studio.
Looking over the .net examples the developer who originally coded the initialization used the one for the console application. The below code is called on every report render, which I think is incorrect.
var rs = new LocalReporting() .KillRunningJsReportProcesses() .UseBinary(JsReportBinary.GetBinary()) .RunInDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar.ToString() + @"bin", "jsreport")) .Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); var report = rs.RenderByNameAsync(ReportName, reportData).Result; MemoryStream ms = new MemoryStream(); report.Content.CopyTo(ms); return ms.GetBuffer();
I think the first block of code should be on the application initialization or start-up but the only example I found that shows how to initialize it there is for a .net core application.
Any help would be greatly appreciated.
Thank you,
Jo
-
Yes, you should reuse the
rs
in your case and call onlyrs.RenderByNameAsync
when it is required to render something.If it is still slow, you can try this.