Using Telerik Reporting in Orchard

Topics: General, Troubleshooting, Writing modules
Mar 31, 2014 at 6:24 PM
I'm trying to integrate Telerik reporting functionality into Orchard. I've created a custom module that serves up a view containing the ReportViewer syntax, as below:
    <div id="reportViewer1" class="k-widget">
        loading...
    </div>
    
    <script type="text/javascript">

    $("#reportViewer1")
        .telerik_ReportViewer({
            serviceUrl: "/api/CustomReports/reports",
            templateUrl: "/Modules/CustomReports/Reports/templates/telerikReportViewerTemplate.html",
            reportSource: {
                report: "~/Modules/CustomReports/Reports/PlayerCurrentContract.trdx",
                parameters: {
                    /*ReportYear: "2003"*/
                }
            },
            viewMode: "ViewModes.INTERACTIVE",
            scaleMode: "ScaleModes.SPECIFIC",
            scale: "1.0"
        });

    </script>
The module attempts to implement the Telerik REST Api in a controller, indentical to the ReportsController in this guide.

My problem is that the ReportViewer's requests to the controller aren't getting through in most cases (verified using Fiddler that the requests are formatted correctly). So for example:
    http://localhost:30301/api/CustomReports/reports/clients/ // Works, response contains a client ID
    http://localhost:30301/api/CustomReports/reports/clients/124902-a308/parameters // returns a 404
I'm almost certain this is a routing issue, but I'm not sure how to solve it. Orchard doesn't easily give you access to a HttpContext for the ReportsControllerConfiguration.RegisterRoutes() call, so I set up a little hack in Orchard.WebApi.DefaultOrchardWebApiHttpHttpControllerActivator class:
            public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) {

            if (!_reportsRoutesRegistered) {
                _reportsRoutesRegistered = true;
                _configuration.Routes.MapHttpRoute(
                    name: "CustomReportsApi",
                    routeTemplate: "api/{controller}/reports/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );
                ReportsControllerConfiguration.RegisterRoutes(_configuration);
            }
            ...
I don't seem to get any exceptions doing this, but obviously something isn't working correctly. I understand that this is a fairly obscure issue (not many posts about using Telerik Reporting in Orchard on the web), but I would greatly appreciate any assistance. Thanks!
Developer
Mar 31, 2014 at 11:25 PM
You need to create a Routes file.... This way you dont have to override core files... an example would be....
    public class ApiRoutes : IHttpRouteProvider {
        public void GetRoutes(ICollection<RouteDescriptor> routes) {
            foreach (RouteDescriptor routeDescriptor in GetRoutes()) {
                routes.Add(routeDescriptor);
            }
        }

        public IEnumerable<RouteDescriptor> GetRoutes() {
            return new[] {
                 new HttpRouteDescriptor {
                    Priority = -10,
                    RouteTemplate = "api/Account/{action}",
                    Defaults = new {
                        area = "Foo.Orchard.Enrolment",
                        controller = "AccountAPI"
                    },
                },
Apr 1, 2014 at 1:22 PM
Thanks Jetski5822. The problem there is that I must have an HttpConfiguration object to pass to Telerik's ReportsControllerConfiguration.RegisterRoutes() method.
Developer
Apr 1, 2014 at 10:42 PM
ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration); ?