Documentos de Académico
Documentos de Profesional
Documentos de Cultura
4.88 / 5, 8 votes
Web Development » Silverlight » HowTo
First Posted 28 Jul 2010
Introduction
One of the most wanted future features in Silverlight is the possibility to c reate business reports using
Reporting Servic es. In this artic le, I will show how to use the existing Reporting Servic es tec hnology
with Silverlight and RIA Servic es c ombination.
Background
I assume that the reader has some basic to intermediate level knowledge in Silverlight and RIA Servic es
and C#, also some knowledge about WCF and the Entity Framework.
codeproject.com/KB/…/SLReporting.asp… 1/17
9/20/2010 Integrate Reporting Services with Silverli…
codeproject.com/KB/…/SLReporting.asp… 2/17
9/20/2010 Integrate Reporting Services with Silverli…
codeproject.com/KB/…/SLReporting.asp… 3/17
9/20/2010 Integrate Reporting Services with Silverli…
codeproject.com/KB/…/SLReporting.asp… 4/17
9/20/2010 Integrate Reporting Services with Silverli…
codeproject.com/KB/…/SLReporting.asp… 5/17
9/20/2010 Integrate Reporting Services with Silverli…
codeproject.com/KB/…/SLReporting.asp… 6/17
9/20/2010 Integrate Reporting Services with Silverli…
Here are all the entities selec ted to be added to the domain servic e:
codeproject.com/KB/…/SLReporting.asp… 7/17
9/20/2010 Integrate Reporting Services with Silverli…
Now we c an add a new Report. In this c ase, we are using Reporting Servic es in Loc al mode.
codeproject.com/KB/…/SLReporting.asp… 8/17
9/20/2010 Integrate Reporting Services with Silverli…
In the report, when a T ablix c omponent is added, a dataset is requested. In this c ase, the Choose the
Dataset Wizard sees the domain c ontext that we added before.
For this demo, I c reated a new c lass that I will use to bind to the report. T here are c ases in whic h that
is preferable to do bec ause we may need to do some extra proc essing before the data c an be bound to
the report:
using System;
using System.Collections.Generic;
codeproject.com/KB/…/SLReporting.asp… 9/17
9/20/2010 Integrate Reporting Services with Silverli…
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace ReportingServicesDemo.Web
{
public class Orders
{
public Orders()
{ }
[Key]
public int OrderDetailsID
{
get;
set;
}
codeproject.com/KB/…/SLReporting.asp… 10/17
9/20/2010 Integrate Reporting Services with Silverli…
In this c lass, I made a referenc e to the System.ComponentModel.DataAnnotations namespac e
that allows me to add a Key attributte to the OrderDetailsID property - that is a requirement for
the c lass so the domain servic e c an rec ognize it as an entity.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.ServiceModel.DomainServices.EntityFramework;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
Now I c reate a domain operation that exposes the Orders entity I just c reated in my c ustom c lass:
Here are some remarks. In this method, I'm using the Entity Framework c ontext instead of the objec t
c ontext that the domain servic e dec lares, and exposing like the other selec t methods as IQueryable.
If we build the projec t again, the "Choose the DataSet Wizard" sees our c ustom method and all the
fields exposed by the entity ready for our report.
codeproject.com/KB/…/SLReporting.asp… 11/17
9/20/2010 Integrate Reporting Services with Silverli…
Now we add a WebForm to the web projec t in order to plac e the report using the ReportViewer
c ontrol:
codeproject.com/KB/…/SLReporting.asp… 12/17
9/20/2010 Integrate Reporting Services with Silverli…
Looking at the ObjectDataSource's properties, we c an see the Selec t property of our c ustom
method.
codeproject.com/KB/…/SLReporting.asp… 13/17
9/20/2010 Integrate Reporting Services with Silverli…
Looking at the SelectParameters c ollec tion, we see our c ustom method parameter.
Now in the Silverlight projec t, we add a DataGrid bound to the Sales Orders entity.
codeproject.com/KB/…/SLReporting.asp… 14/17
9/20/2010 Integrate Reporting Services with Silverli…
Eac h field in the Sales Order ID c olumn is represented as a button just for this demo in order to pass
the c ontent value as a parameter on the c lic k event. T he idea is to c all a popup window using the
HtmlPage objec t, with HtmlPopup options from the System.Windows.Browser namespac e.
if (true == HtmlPage.IsPopupWindowAllowed)
HtmlPage.PopupWindow(new Uri(url), "new", options);
We c an obtain the c urrent web address were the Silverlight XAP applic ation is running, using the
Application.Current.Host.Source.AbsoluteUri property. Later, we c an c reate the URI
assoc iated with the ReportViewer's Web Form.
codeproject.com/KB/…/SLReporting.asp… 15/17
9/20/2010
assoc iated with the ReportViewer's Integrate
Web Form.Reporting Services with Silverli…
Points of Interest
I hope this artic le c an be helpful while we wait for the next Silverlight releases, and also c an explore
more options in business reporting.
History
07- 26- 2010: Submitted to CodeProjec t.
License
T his artic le, along with any assoc iated sourc e c ode and files, is lic ensed under T he Code Projec t Open
Lic ense (CPOL)
Ernesto Herrera Ernesto Herrera is a Senior Developer, Arc hitec t with more than 12 years
experienc e, ac tually working with Silverlight Line- of- Bussiness Applic ations, he
holds a MCT S Web Applic ation 2.0 Certific ation, and have a wide experienc e
Web Developer with sql server sinc e the 6.5 version, on his free time he likes to play tennis
Sigo S.A. with his wife,kids and friends, also enjoy playing Wii with his sons, he works at
Venezuela Sigo S.A., a retail business loc ated at Margarita Island, Venezuela.
Member
codeproject.com/KB/…/SLReporting.asp… 16/17
9/20/2010 Integrate Reporting Services with Silverli…
Follow on Twitter
codeproject.com/KB/…/SLReporting.asp… 17/17