We use the Report Manager for server-side reports; client-side RS brings power to all lines of business applications to access these server-side reports and provide a good user experienc
Trang 1Integrating Server-Side
Reports
In previous chapters, you learned to develop reports using different clients In each chapter,
we developed the reports with clients using Visual Studio In a typical organization, though,
you may find reports with server-side implementation The question is, therefore, can you
integrate this server-side report with your local client? To do so, will you need to rewrite the
report for the client side?
Well, there’s nothing to worry about—you don’t need to rewrite the report You can easily host server-side reports with your favorite client, just as you do reports built on the client side,
and you can make use of server-side reports hosted with corporate reporting portals We use
the Report Manager for server-side reports; client-side RS brings power to all lines of business
applications to access these server-side reports and provide a good user experience
In this chapter, you will
• Explore the remote processing mode
• Learn to access server-side reports with a Windows Forms client
Remote Processing Mode
So far, you’ve set the report processing mode to Local for all the reporting projects In this
chapter, you’ll set the processing mode to Remote for the first time I suspect questions
might be popping up in your mind: What is the real difference between these modes? Will
ReportViewer show reports differently in remote mode?
ReportViewer will show the reports in the same way for both local and remote modes
However, there is a subtle difference in how report processing happens In remote processing
mode, the control brings back a fully processed report from server-side RS If you use the
report mode for the ReportViewer control, the control serves two purposes: it is used as a
viewer, and it provides support for interacting with a report I mean to say, if a report has
parameters, users can specify values for those parameters within ReportViewer
359
C H A P T E R 1 1
Trang 2Unlike in local mode, all remote-mode data processing and rendering is done on the report server and only the output is produced for viewing A report must be published before you can access it with the client, and you can get the report from a stream or by specifying the URL of the report address
■ Note You cannot use rdlcfiles in remote processing mode If you want to publish your rdlcfiles on the server side, you must first convert them to rdlformat For detailed steps for converting rdlcfiles to rdland vice versa, please check the following MSDN link:http://msdn2.microsoft.com/en-us/ library/ms252109(vs.80).aspx
How Server-Side Reporting Works
Server-side processing of reports is easy compared with the client-side report processing As you know, for a client-side report, we need to collect the data We also need to make sure a proper user interface is available for passing the information as parameters For server-side reports, we don’t have to worry with all of that, because the report server takes care of the data collection and processing, and the user interface to supply report parameters comes as part
of the report preview The important characteristics for accessing a server-side report at the client side follow:
• The processing mode
• The report server URL
• The report path You’ll need to specify these three characteristics with the ReportViewer control As usual, you can set these properties using the Properties window (see Figure 11-1) or C# code
As you can see in Figure 11-1, you’ll need to start with setting the processing mode to Remote Next, you’ll need to specify the report server URL The report server URL can be local
or remote For example, if RS is part of your development box, the typical path is http:// localhost/reportserver Finally, you’ll need to specify the report path, which consists of the folder and report names
Let’s move on to access a server-side report with the Windows Forms client now Devel-oping server-side reports is beyond the reach of this book, so instead, we’ll use samples provided by Microsoft You can use reports built with the AdventureWorks database or the sample reports pack
Trang 3Figure 11-1.ReportViewer Properties window for server-side reports
For the example used in this chapter, I’m going to use the Trial Balance report from the Accounting Reports Pack Please check the following Microsoft resource to download and
install the SQL Server 2005 Report Pack for Financial Reporting:
http://www.microsoft.com/downloads/details.aspx?familyid= ➥
D81722CE-408C-4FB6-A429-2A7ECD62F674&displaylang=en
■ Note Remote processing mode requires a licensed copy of SQL Server 2005 Reporting Services
Trang 4Server-Side Reports with the Windows
Forms Client
Accessing server-side reports is easy—and why shouldn’t it be, since the report is ready, with the design and data connectivity, on the server side? All the client application has to do is access the report with help of the ReportViewer control Now, before we access our Trial Bal-ance report, please see Figure 11-2 for a view of the Report Manager window with the report output Later, we’ll compare this output with output produced by the Windows Forms client
Figure 11-2.Report Manager view of the Trial Balance report
Trang 5Creating a Windows Forms Project
Open Visual Studio, and use the following steps to create a Windows application project;
Figure 11-3 illustrates these steps:
1. Click File ➤New ➤Project, or press the hot key Ctrl+Shift+N
2. In the “Project type” pane of the New Project dialog box, select Visual C# ➤Windows
3. In the Templates pane, select Windows Application
4. Please give the application a name; I’ve called the project WinServerSide You may choose a different location for storing the application files according to your preference
5. Click the OK button to finish the process Visual Studio will create a new Windows application project as well as a new form with the name Form1
Figure 11-3.Create a new Windows Application project.
Trang 6If you face difficulty creating the Windows Forms application project, revisit Chapter 4 for detailed instructions on creating a Windows Forms client
Adding the ReportViewer Control
As I mentioned before, if you’d like to view the server-side report with minimal effort on the client side, all you need is the ReportViewer So, let’s add that to the project Select Toolbox ➤
Data ➤ReportViewer, and drag and drop the ReportViewer onto Form1, as shown in Figure 11-4 After you add the ReportViewer to Form1, you can go on to specify server-side report access information by clicking the Tasks button (circled in Figure 11-4)
Figure 11-4.Add the ReportViewer to the project.
Please make sure you set the properties in Table 11-1 After you specify all properties, your Form1 should look similar to Figure 11-5
Table 11-1.Property Settings for the Web Site
Object Property Value
Form1
Text Server-Side Report with Windows Forms
Size 750, 530 reportViewer1 Dock Fill
Trang 7Figure 11-5.Form1 after setting properties
Setting Up the ReportViewer Properties
All right, we’ve got Form1 ready with ReportViewer All we need now is to set properties that will help the ReportViewer to display our Trial Balance report You can set up properties in three
different ways: First, you could use the Properties window, shown in Figure 11-6
Figure 11-6.Setting up ReportViewer using the Properties window
Trang 8Your second choice is to use the ReportViewer task After you drop the ReportViewer control onto Form1, the ReportViewer Tasks pop-up dialog will appear, and you can specify properties using this task dialog (see Figure 11-4) The third choice is to write the C# code to set up the report properties If you decide to write the code, please make sure that the code behind Form1.cs looks like the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace WinServerSide
{
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e) {
// set processing mode to remote reportViewer1.ProcessingMode = ProcessingMode.Remote;
// specify report URL // please make sure to replace localhost with server name if needed reportViewer1.ServerReport.ReportServerUrl = new ➥
Uri(@"http://localhost/reportserver");
// specify report path, Folder = Accounting Report Pack // Report = Trial Balance
reportViewer1.ServerReport.ReportPath = ➥
@"/Accounting Report Pack/Trial Balance";
// show the report this.reportViewer1.RefreshReport();
} } }
Trang 9Server-Side Reports, At Your Service
Now, let’s build the project As you know, you can build a project by clicking the small, green
Play button in the main toolbox or pressing F5 on the keyboard to start the application in
run-time mode
I assume that you’ve properly set all three important properties in ReportViewer, as we discussed earlier in this chapter If all goes well, your project should compile without any
issues, and you should be able to see the Trial Balance report in action; your output should
look similar to Figure 11-7
Figure 11-7.A server-side report in action
If your report looks similar to Figure 11-7, you’ve done it That’s all you need to embed the sever-side report at client-side You may also like to compare the output of Figure 11-7 with
the output of Figure 11-2; almost everything is the same except how the report is accessed
Summary
This chapter discussed the remote processing mode We did a hands-on exercise to access a
server-side report with a Windows Forms client As you can see, developers can take
advan-tage of the server-side reporting portals to bring server-side reporting potential to client-side
business applications
In the next chapter, we’ll look at ways to help you move on from Crystal Reports and enjoy the benefits provided by client-side RS