ASP.NET Core Web API Project Template

Stimulsoft Reports.WEB discussion
Post Reply
DvdKhl
Posts: 3
Joined: Thu Apr 07, 2022 4:25 pm

ASP.NET Core Web API Project Template

Post by DvdKhl »

Hi,

we're currently evaluating multiple Reporting Tools and "Reports.Web" currently fits the bill better than the other Tools.
The only problem is that I'm failing to modify the examples in such a way that I'm able to integrate it into our main Project.

We're using the "ASP.NET Core Web API Project Template" so there is no cshtml/webroot support.

I tried to modify the following examples to fit my needs (Both with net6.0):
https://publish.stimulsoft.com/#NetCore/Angular
https://publish.stimulsoft.com/#Mvc

The Angular example more closely fits my needs on the server side, but since we are using vue instead of angular I don't know how to integrate that on the client side.
The Mvc example makes it easy to integrate it into the client but uses cshtml/webroot which is not available in our main server side project.

It would be very nice if someone could extend the attached Probject (basically just the default WebApi Template) in such a way that the ReportViewer/ReportDesigner is accessible by the browser either without any client side frameworks or just using vue.
Attachments
StimulSoft.Reporting.WebApi.zip
(87.39 KiB) Downloaded 148 times
DvdKhl
Posts: 3
Joined: Thu Apr 07, 2022 4:25 pm

Re: ASP.NET Core Web API Project Template

Post by DvdKhl »

I've made a step forward and I'm now able to open the Report Viewer an Designer by just pointing the browser to a url.

My current approach however is a workaround at best:
- I've Downloaded the "ASP.NET MVC" "MVC" "NET6.0" "File" ("Show" / "Design") Projects from https://publish.stimulsoft.com/
- Started each project, captured the html output from the "Index" Endpoints and saved them to StiViewer.html and StiDesigner.html
- Created a new Project which used the "ASP.NET Core Web API" template
- Copied the HomeController in the Designer Example as DesignerController and the HomeController in the Viewer Example as ViewerController
- Added the RouteAttribute "[Route("/Designer")]" and [Route("/Viewer")] respectively to each controller
- Copied each Endpoint Method except the Index one (Appended a "2" to the duplicate) and added HttpGet/HttpPost respectively Attributes to them
- Included both html files
- Modified both html files so the options properly point to the Backend
- Modified the Index Endpoint Method to return the static html file

So this is definitely possible but the static html files approach is too ugly. But I haven't found a way to generate the html code on demand yet.
DvdKhl
Posts: 3
Joined: Thu Apr 07, 2022 4:25 pm

Re: ASP.NET Core Web API Project Template

Post by DvdKhl »

ViewerController for example:

Code: Select all

using Microsoft.AspNetCore.Mvc;
using Stimulsoft.Report;
using Stimulsoft.Report.Mvc;

namespace StimulSoft.Reporting.WebApi.Controllers
{
    [Route("/Viewer")]
    public class ViewerController : Controller
    {
        [HttpGet]
        public ContentResult Index()
        {
            var content = System.IO.File.ReadAllText("StiViewer.html");
            return Content(content, "text/html");
        }

        [HttpGet("GetReport")]
        public IActionResult GetReport()
        {
            var report = StiReport.CreateNewReport();
            var path = StiNetCoreHelper.MapPath(this, "Reports/Report.mrt");
            using (var stream = System.IO.File.OpenRead(path))
            {
                report.Load(stream);
            }

            return StiNetCoreViewer.GetReportResult(this, report);
        }
        [HttpPost("GetReport")]
        public IActionResult GetReport2()
        {
            var report = StiReport.CreateNewReport();
            var path = StiNetCoreHelper.MapPath(this, "Reports/Report.mrt");
            using (var stream = System.IO.File.OpenRead(path))
            {
                report.Load(stream);
            }

            return StiNetCoreViewer.GetReportResult(this, report);
        }

        [HttpGet("ViewerEvent")]
        public IActionResult ViewerEvent()
        {
            return StiNetCoreViewer.ViewerEventResult(this);
        }
        [HttpPost("ViewerEvent")]
        public IActionResult ViewerEvent2()
        {
            return StiNetCoreViewer.ViewerEventResult(this);
        }
    }
}
I've added the updated Project (I've stripped the Source code from the html files since I'm not sure if I'm allowed to post that code here)
Attachments
StimulSoft.Reporting.WebApi.v2.zip
(174.35 KiB) Downloaded 206 times
Lech Kulikowski
Posts: 6244
Joined: Tue Mar 20, 2018 5:34 am

Re: ASP.NET Core Web API Project Template

Post by Lech Kulikowski »

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
Post Reply