This is a migrated thread and some comments may be shown as answers.

Using Telerik Reporting in Orchard CMS

4 Answers 173 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 31 Mar 2014, 05:13 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:

            private bool _reportsRoutesRegistered;
            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!

4 Answers, 1 is accepted

Sort by
0
KS
Top achievements
Rank 1
answered on 03 Apr 2014, 04:27 PM
Hi,

Can you post the Raw response of the request from Fiddler. There is something in the configuration preventing the requests to the controller. Update also the Json reference from Nuget to 6.0.1.

-KS
0
William
Top achievements
Rank 1
answered on 03 Apr 2014, 04:30 PM
I was able to resolve this issue by removing the ReportsControllerConfiguration.RegisterRoutes() call and manually create routes for the API requests, as below. Thank you for your response.

using Orchard.Mvc.Routes;
using System.Collections.Generic;
using System.Web.Http;

namespace CustomReports
{
    public class Routes : IRouteProvider {

        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        public IEnumerable<RouteDescriptor> GetRoutes() {
            return new[] {

                new HttpRouteDescriptor {
                    Name = "Register Client / Unregister Client / Get Available Document Formats",
                    RouteTemplate = "api/CustomReports/{controller}/{action}/{clientID}/",
                    Defaults = new {
                        area = "CustomReports",
                        clientID = RouteParameter.Optional
                    }
                },

                new HttpRouteDescriptor {
                    Name = "Get Report Parameters / Create Report Instance / Destroy Report Instance",
                    RouteTemplate = "api/CustomReports/{controller}/clients/{clientID}/{action}/{instanceID}",
                    Defaults = new {
                        area = "CustomReports",
                        instanceID = RouteParameter.Optional
                    }
                },

                new HttpRouteDescriptor {
                    Name = "Get Document Info",
                    RouteTemplate = "api/CustomReports/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/info",
                    Defaults = new {
                        area = "CustomReports",
                        action = "documentinfo"
                    }
                },

                new HttpRouteDescriptor {
                    Name = "Create Document / Get Document / Destroy Document",
                    RouteTemplate = "api/CustomReports/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}",
                    Defaults = new {
                        area = "CustomReports",
                        documentID = RouteParameter.Optional,
                        action = "documents"
                    }
                },

                new HttpRouteDescriptor {
                    Name = "Get Document Page",
                    RouteTemplate = "api/CustomReports/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/pages/{pageNumber}",
                    Defaults = new {
                        area = "CustomReports",
                        action = "documentpages"
                    }
                },

                new HttpRouteDescriptor {
                    Name = "Get Document Resource",
                    RouteTemplate = "api/CustomReports/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/resources/{resourceID}",
                    Defaults = new {
                        area = "CustomReports",
                        action = "documentresources"
                    }
                },

                new HttpRouteDescriptor {
                    Name = "Apply Interactive Action On Document",
                    RouteTemplate = "api/CustomReports/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/actions/{actionID}",
                    Defaults = new {
                        area = "CustomReports",
                        action = "documentactions"
                    }
                }

            };
        }
    }
}
0
Rob
Top achievements
Rank 1
answered on 16 Apr 2014, 08:07 PM
Thank you William. This helped a lot.

I have been trying to get a WebApi only project containing the Telerik Report Engine to deploy to a virtual directory (https://localhost/api) but ReportsControllerConfiguration.RegisterRoutes makes all of the routes for the engine route from http://localhost/api/api/{controller} which was driving me nuts.

If there is a better way to configure the report engine to not hard code "api/" in front of all routes I'd love to hear from Telerik about it.

Thanks again.
0
Stef
Telerik team
answered on 18 Apr 2014, 10:41 AM
Hello Rob,

To ease the registering of the routes to the Reporting WebAPI we provide a RegisterRoutes method:
ReportsControllerConfiguration.RegisterRoutes(GlobalConfiguration.Configuration)
The method above uses /api to distinguish requests to custom controllers by requests to API controllers. Mode details about this convention can be found in the Routing in ASP.NET Web API MS ASP.NET tutorial.

If your custom settings conflict with the default routes, you can extract the list of registered for our WebAPI routes from the GlobalConfiguration.Configuration, change the /api part in the routes, remove the old and add the new routes.

You can use the browser's Console or proxy tool as Fiddler to check if the customize routes work properly in your application.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
William
Top achievements
Rank 1
Answers by
KS
Top achievements
Rank 1
William
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Stef
Telerik team
Share this question
or