In part 1 we created an end-user report designer that can publish reports to a database using OData protocol. Now, let’s create a Silverlight application that can view the reports that we have published.
Report Service
First we’ll add a printing service to our ASP.NET host application.
By default Silverlight-enabled XtraReports Service looks up the reports by type name, we want to override this behavior and load the report from the database.
protected override XtraReport CreateReport(
string reportTypeName,
Dictionary<string, object> parameters) {
try {
using (List listService = new List()) {
using (Session session
= new Session(listService.GetDataLayer())) {
Report report
= session.GetObjectByKey<Report>(new Guid(reportTypeName));
if (report == null) {
return Create404Report();
}
File file = report.File;
if (file == null) {
return Create404Report();
}
XtraReport retVal = new XtraReport();
using (MemoryStream stream = new MemoryStream(file.Binary)) {
retVal.LoadLayout(stream);
return retVal;
}
}
}
} catch (Exception e) {
return Create500Report(e);
}
}
Note: The assumption of the new CreateReport is that the reportTypeName is a report ID, a GUID.
Silveright Viewer
Inside the Silverlight, we’ll simply drop the DocumentPreview control on our page and load the report on page load. I have described this process here.
<dxp:DocumentPreview Name="documentPreview1"/>
void MainPage_Loaded(object sender, RoutedEventArgs e) {
if (!HtmlPage.Document.QueryString.ContainsKey("id")) {
return;
}
string reportId = HtmlPage.Document.QueryString["id"];
if (string.IsNullOrWhiteSpace(reportId)) {
return;
}
ReportPreviewModel model
= new ReportPreviewModel(
new Uri(App.Current.Host.Source.AbsoluteUri + "../../ReportService.svc").ToString());
model.ReportTypeName = reportId;
documentPreview1.Model = model;
model.CreateDocument();
}
That’s it, we can now access our reports by a URL for example
http://localhost.:56844/Report.aspx?id=7750954ac4b749a2a41c70f419e741c2
Final Notes
- You can download the complete sample here.
- The included Web.config will be useful to you if you need to copy paste some settings.
- You will also need DevExpress.Xpo.Services.10.1.dll this file is not included in the provided sample but you can download it from http://xpo.codeplex.com.
- Get more information and more samples of OData Provider for XPO.
Cheers
Azret