Here are the first 2 parts of this article:
How to Display SQL Server Reporting Service Reports in Silverlight
How to Display SQL Server Reporting Service Reports in Silverlight (Part 2)
Custom Rendering Extension
The main shtick of our approach is that we implement custom XAML rendering extension and set it on the SSRS side. This allows us to provide a user with reports in native Silverlight look. Thus, the report’s look & feel is much better in comparison with HTML document.
Let’s learn how to implement custom rendering extension.
In order to create custom Rendering Extension I need to implement Microsoft.ReportingServices.OnDemandReportRendering.IRenderingExtension interface.
The Render method should implement the logic of the report handling.
You can read more detailed description of IRenderingExtension on the MSDN site.
In my case, XAML rendering extension converts report prepared with the help of the handler (Report processing extension) to the format able to display in SL Viewer.
XAML Rendering Extension queries the report object model (DOM-model) from SSRS. After this, it is parsed and converted. During the conversion there created XAML templates for each report page, resources’ collections which include images of graphic objects such as Image, Chart, Gauge and etc. The result of work of the rendering extension is the object which includes data about the report, all pages in the XAML format and resources used in the report.
Interaction of WCF and SSRS
As it was said above, the interaction between the client part on Silverlight and SSRS is executed with the use of WCF service. Let’s examine this interaction in detail.
Web-reference service is added to ReportExecutionService for interaction of WCF service and SSRS. ReportExecutionService is a standard SSRS service which allows the program control of the report rendering. The service is available at
http(s):////ReportExecution2005.asmx.
Please note that 2005 year in URL is indicated even if you work with RS for SQL Server 2011. Maybe, at first, this URL appeared in SQL Server 2005, and then it remained unchanged because of compatibility.
I won’t go into detail of ReportExecutionService description. You can view precise description on MSDN site.
I will only add that the basic methods necessary to get the ready report are:
- LoadReport
- SetExecutionParamaters
- Render
Interaction of Silverlight and WCF
In order to display a report I need to get general information about it as well as XAML for the pages display.
When a report is queried, Silverlight application refers to WCF service to get data about the report. At first, the report identifier is got, and then its parameters installation is executed (if necessary). When the parameters’ values are set, report rendering is executed.
In order to execute report rendering, Silverlight app sends the query to WCF service. WCF service handles the query from Silverlight app, and, in its turn, sends the query to SSRS.
To render the report, I should invoke the Render method of the ReportExecutionService class. One of the method’s parameter is format to which rendering should be executed. This parameter defines what extension will be used by SSRS for report rendering. In my case, I need to indicate XAML Rendering Extension.
When the report was rendered on SSRS and the report was got by WCF service, the report is located to cache on WCF. Report meta-data returns to Silverlight app as a result of the rendering query. These meta-data includes report title, number of pages, bookmarks tree, etc.
When meta-data is got, the Silverlight application builds model for the report display. The document’s model and the objects for storing the content of each page are created, initialization of bookmarks’ tree and thumbnails is executed.
The report content is queried page-by-page. The page is queried when it is in the view area. Such approach allows a user to start the work with the report immediately without waiting till the whole report is loaded from the server. Taking into account that the report can include several thousands of pages, the page-by-page loading is really necessary.
Thus, a user has the ability to quickly and comfortably preview reports got from SSRS in Silverlight. And developers get a powerful tool for implementing reports in their applications.
In brief, this is all that I want to share with you today. If you have any questions please send them to [email protected]. We will be glad to answer!