Telerik reports without trdx files

2.2k views Asked by At

I am banging my head against the brick to get this working. I have reports which are generated using report designer and they are working fine as i have loaded them using an iframe now i want to use Html5 report viewer. But in most of the tutorials out there they are using trdx reports rather than one being generated using report Designer.

I have a class library named XYZ.TelerikReports where all the reportname.cs (reports ) files resides and i have my main project in the same solution where i want to show the reports.

$("#reportViewer1")
        .telerik_ReportViewer({
            serviceUrl: "/api/reports/",
            templateUrl: '/ReportViewer/templates/telerikReportViewerTemplate.html',
            reportSource: {
               report: "XYZ.TelerikReports.IncomeStatementReport,XYZ.TelerikReports" 
                parameters: { ReportDataID: parseInt('@state.CurrentReportDataID') } 
            },

            scale: "1.0"
        });

Now i am wondering what should be my serviceUrl ?

2

There are 2 answers

0
Peadar Doyle On

The serviceUrl expects to be routed to the Telerik Reporting Web API controller. The current value you use /api/reports/ is Telerik's default name for this controller. The documentation details how to implement the Web API controller pretty well. You'll find that here http://www.telerik.com/help/reporting/telerik-reporting-rest-host-http-service-using-web-hosting.html and here http://www.telerik.com/help/reporting/telerik-reporting-rest-implementing-http-service.html.

This controller will resolve the requested report successfully if the report name is that of a report class or a .trdx. Alternatively you can implement a customer report resolver. This can be done by following the instructions in the documentation here http://www.telerik.com/help/reporting/telerik-reporting-rest-custom-report-resolver.html.

So your serviceUrl is fine. You just need to make sure that you have the service it calls setup.

0
Kofi Amparbeng On

One possible Approach is to modify your reporting API controller to use the report type resolver and alter the CreateReportResolver e.g.

protected override IReportResolver CreateReportResolver()
        {
            var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");

            return new ReportTypeResolver()
                            .AddFallbackResolver(new ReportFileResolver(reportsPath));
        }

Then specify the Fully Qualified Assembly name or classname of each report in the HTML5 Viewer Configuration (as you are already doing). With regards to the path for the service url, you can use the api/reports route you have above, but you must call the telerik reporting route registration function in your WebApiConfig.Register function, i.e.:

ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration);

This means your reporting api is inside a controller called ReportsController.

Alternatively, you can customize the path to something like /Controllers/MyCustomReports by implementing your own reporting routes registration function and calling it instead of the above snippet. For instance, you can have:

private static void RegisterReportingRoutes(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(name: "Clients",
         routeTemplate: "Controllers/{controller}/clients/{clientID}",
         defaults: new { controller = "MyCustomReports", action = "Clients", clientID = RouteParameter.Optional });

        config.Routes.MapHttpRoute(
            name: "Instances",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}",
            defaults: new { controller = "MyCustomReports", action = "Instances", instanceID = RouteParameter.Optional });

        config.Routes.MapHttpRoute(
            name: "DocumentResources",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/resources/{resourceID}",
            defaults: new { controller = "MyCustomReports", action = "DocumentResources" });

        config.Routes.MapHttpRoute(
            name: "DocumentActions",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/actions/{actionID}",
            defaults: new { controller = "MyCustomReports", action = "DocumentActions" });

        config.Routes.MapHttpRoute(
            name: "DocumentPages",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/pages/{pageNumber}",
            defaults: new { controller = "MyCustomReports", action = "DocumentPages" });

        config.Routes.MapHttpRoute(
            name: "DocumentInfo",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/info",
            defaults: new { controller = "MyCustomReports", action = "DocumentInfo" });

        config.Routes.MapHttpRoute(
            name: "Documents",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}",
            defaults: new { controller = "MyCustomReports", action = "Documents", documentID = RouteParameter.Optional });

        config.Routes.MapHttpRoute(
            name: "Parameters",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/parameters",
            defaults: new { controller = "MyCustomReports", action = "Parameters" });

        config.Routes.MapHttpRoute(
            name: "Formats",
            routeTemplate: "Controllers/{controller}/clients/{clientID}/formats",
            defaults: new { controller = "MyCustomReports", action = "Formats" }); 
    }

Note that you should reference the reports library from the solution containing the REST services.