Demystifying DevExpress XtraReport for Silverlight - Part 4
This is the second step of the tasks - probably this should have been done first but it should not really mater. As you may recall, for Silverlight applications using Devexpress report control, the report is implemented as a Client-Server process using web services. Essentially, a web service call is made from the server which in turn runs the report and then returns an XAML representing the formatted report to the client.
So, a web service needs to be installed on the server for this purpose. DevExpress has a template web service in place - so, all that is needed is use it and then do any house cleaning necessary. Just to get you in the right frame of mind - this is like a clearing house for all reports to be printed. Here, for each report requested, one needs to instantiate it before it can run.
To set this up, select the Server side or Web project for the Silverlight application. Then, right click and select "DXperience vxx Report Service". The only thing that needs to be done in this unit is to override the CreateReportByName method. Within this method, individual reports will be instantiated. Since there may be many reports, the trick is to come up with a generic way of doing this without having to hard code class name for every report to be instantiated.
Below is a sample content of the report service file. Essentially, I have introduced generic routines to instantiate the report classes much more easily than you will find in some of the online examples. One more thing to add, setting up the report service also adds an MDB file as well as a sub folder - APP DATA. My inquiries from DevExpress gives the impression that - it is something internally used by DevExpress code for the purposes of the report and it it is not even required. If it is not found, in-memory objects will be created to achieve the same thing. Just take it that - it is something required by DevExpress to run the Report service.
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using DevExpress.Data.Utils.ServiceModel; using DevExpress.Xpf.Printing.Service; using DevExpress.XtraReports.Service; using DevExpress.XtraReports.UI; using IdeaBlade.Core; using IdeaBlade.EntityModel; namespace CCA_Silverlight_600.Reports { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "DevExpressReportingService" in code, svc and config file together. [SilverlightFaultBehavior] public class DevExpressReportingService : DevExpress.XtraReports.Service.ReportService { private static string GetReportNameTokenByIndex(string reportname, char Demarcator = ';', int index = 0 ) { string[] s = reportname.Split(Demarcator); return s[index]; } private static XtraReport GetXtraReport(string className) { { // XtraReport class exists, create it and invoke LoadDataSource. Type reportType = Type.GetType(className); var obj = Activator.CreateInstance(reportType); return (XtraReport)obj; } } protected override XtraReport CreateReportByName(string reportName) { // Create a XtraReport instance depending on passed reportname XtraReport xr = GetXtraReport(GetReportNameTokenByIndex(reportName)); return xr; } } }
Comments
Post a Comment