Due to the rising popularity of Rich Internet Applications (RIA) e.g. Silverlight applications, the developers get more dependent on services for coordinating application logic between the middle tier and the presentation tier and the logical question raises how to use an already working WCF RIA Service as a datasource for Telerik Report. This is very useful if you want to enable the exact same business data access logic for clients other than Silverlight. For example to a WPF, WinForms or WebForms application. Thus we have made some tests locally and decided to share our observations in this post.

Prerequisites:

We will examine the WCF RIA services from Telerik Reporting point of view, so previous basic knowledge on WCF, RIA Services and Telerik Reporting is required and will help you understand the key concepts below. If you are new to this technology the WCF RIA Services Get Started page is the ideal place to start. Another recommended reading is the MSDN Walkthrough: Creating a RIA Services Solution article. We have included a sample WCF RIA service that uses the AdventureWorks database that we would use for our tests.

What you should have installed prior starting:

Introduction:

In Telerik Reporting, Reports represent an abstract definition of the data to be displayed and the way it is displayed. At runtime the reports are processed and rendered by the reporting engine. Its main responsibilities are to extract the data from the data sources and render it according to the layout and styles from the Report definition. There are two ways one can interact with the report processor:

  • Through the Telerik.Reporting.Processing.ReportProcessor class; this class represents the API of Telerik’s reporting engine and this is the way to access the reporting engine when it is embedded in your application. You can use this API explicitly when you need to process and render reports programmatically or implicitly through the WebFormsWinForms and WPF report viewers. In both cases the reporting engine runs locally in your application i.e. it is embedded in it.
  • The Telerik Reporting WCF Service represents the remote interface to the reporting engine. This allows the reporting engine to be hosted in one process (service) and accessed from another process (client). This is how the Silverlight Report Viewer uses the reporting engine but there are no limitations to the clients. As this is a WCF service all WCF rules and concepts are applicable to the Telerik Reporting WCF service.

In RIA Services, you expose data from the server project to client project by adding domain services. The RIA Services framework implements each domain service as a Windows Communication Foundation (WCF) service. Therefore, you can apply the concepts you know from WCF services to domain services when customizing the configuration. For more information, see Domain Services article.

As explained above, the reporting engine accesses the data from the data source. When it comes to consuming that data from a WCF RIA service and depending on the domain service location, we recognize two scenarios:

Remotely available domain service

In this scenario the domain service is hosted in a process different than the one hosting the reporting engine. In order to consume data from such domain service one should create a service client and use it through the ObjectDataSource Component.

remotely available domain service 

To set a WCF RIA Service as datasource for Telerik Reporting you have to:

  1. Add Service Reference to the project containing the report. The domain service would be created automatically.
  2. Add a partial class to extend the domain service soap client with a method that returns RootResults that are acceptable for the ObjectDataSource:

    public partial class AdventureWorksDomainServiceSoapClient 
        {
            public IEnumerable<Product> GetProductsResult()
            {
                var result = this.GetProducts();
                return result.RootResults;
            }
        }

    Public Partial Class AdventureWorksDomainServiceSoapClient
        Public Function GetProductsResult() As IEnumerable(Of Product)
            Dim result = Me.GetProducts()
            Return result.RootResults
        End Function
    End Class

     
  3. Assign the GetProductsResult method to the DataSource property of the ObjectDataSource component

Note: In order to consume domain services from clients other than Silverlight you have to enable SOAP endpoints for your WCF RIA service. A nice explanation on this matter is available in the Silverlight 4 + RIA Services - Ready for Business: Exposing WCF (SOAP\WSDL) Services post.

Locally available domain service

In this scenario the reporting engine and the domain service reside in the same application. This means that the reporting engine can use the domain service class as you do with any other .NET class withough the need of the WCF infrastructure.

locally available domain service

Again you use the ObjectDataSource to connect to the domain service class.

// 
// objectDataSource1
// 
this.objectDataSource1.DataMember = "GetProductsResult";
this.objectDataSource1.DataSource = typeof(WpfApplication1.ServiceReference1.AdventureWorksDomainService1SoapClient);
this.objectDataSource1.Name = "objectDataSource1";

 

' objectDataSource1
Me.objectDataSource1.DataMember = "GetProductsResult"
Me.objectDataSource1.DataSource = GetType(WpfApplication1.ServiceReference1.AdventureWorksDomainService1SoapClient)
Me.objectDataSource1.Name = "objectDataSource1"

 

Having the domain service on site, means that you most probably have access to the data model which means that you can even use it as a report data source. For example if this is ADO.NET Entity Data Model you can use the EntityDataSource Component to connect the report to the data model.

 

Note: Currently the Report Designer can't get the schema of the data source because of WCF RIA services' peculiarities. Thus be aware that the available wizards and Data Explorer would not be populated with data source fields and both Previews would not work.

Conclusion

WCF RIA Services simplifies the development of n-tier solutions and gives excellent separation of the data and application logic from the presentation. In combination with the powerful WCF technology you can create Rich Internet Applications (RIA) with the best user experience without the need to develop and maintain the same application logic on both server and client sides. The two technologies together allow the Telerik Reporing engine to consume data from any WCF RIA Services in a seamless manner without breaking the best architecture patterns.

 

Click here to download a sample solution that contains both approaches.


About the Author

Stefan Tsokev

Stefan’s main interests outside the .NET domain include rock music, playing the guitar and swimming.

Related Posts

Comments

Comments are disabled in preview mode.