After working a bit with the Silverlight Report Viewer for Telerik Reporting, it seemed only natural to write a quick post to explain how exactly the Reporting WCF Service (located here in the help file) works and how to quickly and easily get started with it.

To start with, why do we need a WCF service for Telerik Reporting?  The answer is that we added a Silverlight Report viewer not too long ago, and in order to get information to a Silverlight client application you need to either use a javascript bridge through the webpage hosting the XAP, which is a slightly clunky solution for anything besides using Silverlight as an island of rich functionality within a pre-existing Ajax site, or you can use a web service.  Since WCF is quickly becoming the standard service to use for all things Silverlight, we figured what better way to go than provide a WCF service that streams report data to our viewer, saving you the hassle of trying to figure this out for yourself.

Now we understand the why, how about the how?  In the most basic sense, getting set with the Reporting WCF service can be handled in a few easy steps:

  1. Create the ReportService.svc file in your .Web application
  2. Copy the service line from the help file here and place it into that file
  3. Modify the version number of the report service (listed as X.X.X.X in the webpage) to your current version
  4. Copy the service code from that same page to your web.config
  5. Point the ReportServiceUri property of your Silverlight Report Viewer to that service
  6. Point the Report property of your viewer to the fully qualified name of your report
  7. Build, run, complete!

You can actually see this entire process in action in the Getting Started with the Telerik Silverlight Report Viewer video on Telerik TV.  But what if you want to go a little further?  Thankfully, this WCF service is built to offer a bit more functionality than just pointing Reporting to a single report, and here's how...

First, you want to take advantage of the ReportServiceClient that is located in Telerik.Reporting.Service.SilverlightClient assembly.  This allows you to get a list of reports that are available to the service.  Once you have these, you can easily load them into the Silverlight Report Viewer.  Here is a quick sample of code to show you how this is done:

    public partial class MainPage : UserControl
        public ReportServiceClient ServiceClient;
        public IList<ReportInfo> MyReports;
        public MainPage()
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        void MainPage_Loaded(object sender, RoutedEventArgs e)
            ServiceClient = new ReportServiceClient(ReportViewer.EnsureAbsoluteUri(new Uri("../ReportService.svc", UriKind.RelativeOrAbsolute)));
            ServiceClient.ListAvailableReportsCompleted += new EventHandler<ListAvailableReportsEventArgs>(ServiceClient_ListAvailableReportsCompleted);
        void ServiceClient_ListAvailableReportsCompleted(object sender, ListAvailableReportsEventArgs e)
            this.MyReports = e.Reports;
            // Decide which report to load, or place them into a RadComboBox to let the user select different reports!
            if (this.MyReports.Count > 0)
                this.xReportViewer.Report = this.MyReports[1].FullName;                

To run through what we're doing here, we first set up a ReportServiceClient to use, which in the Loaded event will be created based on the ReportService.svc that we already have generated.  Once this is set, we call the ListAvailableReportsCompleted async method to grab a list of the reports available.

Once that returns back, we can populate the IList<ReportInfo> collection with the e.Reports result- each of these ReportInfo items contains both the regular name (useful for placing in a ListBox, RadComboBox, etc.), as well as the FullName, which is the fully qualified name that you can set to SilverlightReportViewer.Report to load your report.  It really is as easy as that!

Stay tuned, next time we're going to go in-depth on how you can utilize the Reporting WCF service to stream report data to a few other Telerik controls so you can see some of the extra versatility of this service.

About the Author

Evan Hutnick

works as a Developer Evangelist for Telerik specializing in Silverlight and WPF in addition to being a Microsoft MVP for Silverlight. After years as a development enthusiast in .Net technologies, he has been able to excel in XAML development helping to provide samples and expertise in these cutting edge technologies. You can find him on Twitter @EvanHutnick.

Related Posts


Comments are disabled in preview mode.