RBServer PDF
RBServer PDF
Server Edition
Developer’sGuide
Second Edition
Server Edition
Developer's Guide
Copyright © 2002 - 2007 by Digital Metaphors Corporation
i
CONTENTS
SERVER FUNDAMENTALS
Report Application vs. Report Server Application ..............................................3
Socket To Me .....................................................................................................5
Building a Report Server Application .................................................................7
Talking To The Server From A Thin Client ........................................................9
Registering Reports With The Server ..............................................................11
Spelunking With The Report Explorer .............................................................15
Publishing Reports to the Web ........................................................................17
Making Web Browser Content Printable With PDF .........................................19
Troubleshooting the WebTier ..........................................................................21
FAQ .................................................................................................................23
TUTORIALS
Building a Report Server Application for Reports on Forms
Overview ..........................................................................................................29
Copy Existing Report Application to a New Directory ......................................29
Convert the Application to a Server .................................................................30
Register the Reports On the Server ................................................................30
Make the Data Access Components Thread-Safe ..........................................30
Run the Server Application ..............................................................................31
Create a Thin-Client Application ......................................................................31
Building a Report Server Application for Reports in Files
Overview ..........................................................................................................33
Copy Existing Report Application to a New Directory ......................................33
Create a Thread-Safe Data Module .................................................................34
Register the File-Based Reports ......................................................................34
Move the Report Event Handlers to the Data Module .....................................34
Convert the Application to a Server .................................................................35
Run the Server Application ..............................................................................35
Create a Thin-Client Application ......................................................................36
In ReportBuilder Server Edition, this application is Any objects which were passed freely between
divided into two parts: client and server. The server these two areas in the standard reporting applica-
portion of the application will contain the data tion will now be passed across the network.
access components and the reports. The client por-
tion of the application will contain the Preview
Form and any devices necessary to process the
pages.
Obviously the complexity of this reporting solution The Server Edition makes this conversation happen
is much greater than the complexity of the standard via a technology known as sockets (depicted in the
application; two applications must communicate in diagram below); a topic we discuss briefly in the
order for this solution to function effectively. next section.
Socket To Me
SERVER FUNDAMENTALS 5
The nature of this conversation is as follows:
Socket To Me
In the Server Edition communication between the
server and client application occurs via sockets. A
low level feature of the Windows operating sys-
tem, sockets were invented by the team which
modified Unix in order to create the early internet. Sockets give us an excellent pipeline for bytes –
To function properly, sockets require a machine but objects are hardly bytes. Before we can send an
address (IP address like 192.168.1.120) and a port object over the wire, we must convert it to a
(number between 1 – 65535.) Given these values, stream. This is done using a customized version of
two-way communication can be established Delphi streaming. Once an object has been con-
between applications. verted to a stream, it is compressed, converted to
alphanumeric characters (Base64), wrapped in the
When creating a report server application, the Port
body of a SOAP message and sent, piece-by-piece
property of the rsServer component is used to
through the socket to the client. The client reas-
establish the port to which the application will “lis-
sembles the stream, extracts the element from the
ten” when communicating with clients. Of course,
SOAP message and then uses the same customized
you should avoid port numbers which conflict with
Delphi streaming logic to instantiate an exact rep-
other applications that may be running on the
lica of the original object. When the client needs to
server machine.
send a message to the server, the same sequence
Ports for typical services appear in the table below. occurs in the opposite direction.
ftp 21
telnet 23
smtp 25
http 80
pop3 110
nntp 119
our app working by configuring the ServerConnec- We know this report exists on the server and so we
tion and then setting the VolumeName and Report- just hard-code the values. When the Print method
Name properties at run-time. is called, the ClientReport component will commu-
nicate with the server, asking for the first page of
the report named “By Quarter” in the “Account-
ing” volume. Using the information we supplied in
the RegisterReport call, the server will instantiate
an instance of our report form and run the report.
Next we add the name of the unit containing the As you can see, there is not much to serving report
DADE plug-in used for these reports to the uses archives, it’s by far the easiest way to get a server
clause of our data module (in this case, up and running. Archives are the best way to serve
daDBBDE.) We compile the Report Server appli- reports when lots of users want to access the same
cation and run. The reports should now function report and interactive search criteria (where the
properly from the client. user enters the search criteria) are not needed.
That is, unless some of them call RAP pass-thru Registering End-User Reports
functions. If this is the case, we need to add the unit The end-user solution provided by ReportBuilder
containing the pass-thru functions to our applica- organizes reports in a folder tree structure. This
tion. If the functions are registered in the initializa- structure is stored in two database tables: a folder
tion section of their unit (which is usually the case) table and an item table. Almost all items are reports
then we are done. Recompile and run. (though some may be exported data modules or
You’ll notice that registering reports is more about code modules.) The trick, of course, is how to
creating a habitat conducive to report generation, serve this more complex structure. It’s not simply a
than it is about understanding the ins and outs of directory with templates or archives in it. This
the volume components. The volume components problem is so fundamental, that the concept of
are actually quite simple, representing little more folders became “the way” to model all volumes.
than a location (and the associated access mecha- Both the TemplateVolume and ArchiveVolume
nism) for a given set of reports. No volume illus- can handle subfolders, and automatically display
trates this more clearly than the subfolders when they are configured. The end-user
ReportArchiveVolume. folder structure can be served via the ReportEx-
plorerVolume. The name refers to the Report
Registering Report Archives Explorer, which normally displays the folders and
Report Archives are reports which have been gen- items in an end-user application. The same config-
erated and saved to a file or to a database BLOB uration conditions apply to end-user reports as to
field. Because the generation cycle is complete, no any template based reports: a database connection
database objects are needed when previewing the is needed, any RAP pass-thru functions which have
reports. This greatly simplifies the task of serving been used in the reports are needed, and the unit
report archives. Assuming we have a system direc- name for the DADE plug-in must be included in
tory stocked with report archive files, we can regis- the uses clause. So let’s configure a
ter these by creating a new data module in the ReportExplorerVolume and see just how easy (or
Server Application, adding a ReportArchiveVol- difficult) it is.
ume and setting the FileDirectory property. Once
First, we open the Server Application and add a
we compile and run these reports will be available
new data module to the project. We place a
from the client app. Also, any archive files we add
ReportExplorerVolume in it. Then we open the
to this directory will appear on the client the next
main form containing our end-user solution. From
time the client takes a fresh look at the given vol-
this we copy the data access components for the
ume. In other words the directory is now “hot”,
folder and item tables.
and anything we add to it will be served to clients.
Registering Reports With The Server
SERVER FUNDAMENTALS 13
We paste these into the data module. Next we add
database connection objects: for this example we
need a TDatabase and a TSession object. We set
the TSession.AutoSessionName property to True
so that it is thread-safe. We add the unit name for
the DADE plug-in to the uses clause (in this case
daDBBDE) and that’s it. We’re ready to go. The
steps necessary to configure the database connec-
tion for any given database (and database connec-
tivity product) will vary. See the examples in
RBServer\Demos\Explorer Databases for an exam-
ple of your database/data connectivity product.
Spelunking With The Report Explorer
SERVER FUNDAMENTALS 15
Spelunking With The Report Explorer
We have created quite a collection of reports on the The screen-shot below shows what happens when
server with all of this registration activity. We have we run this application and click the Launch but-
a report on a form, a set of reports in an operating ton. It’s the same old Report Explorer from the
system directory, a set of report archives in an end-user application, only this explorer is running
operating system directory and a set of reports in across the wire, and is displaying reports from a lot
an end-user database. While the report catalog and more sources than just the end-user database
volume naming scheme ensures that we do not tables.
have a report name collision on the server, things
are about as clear as mud on the client side. There
are far too many reports to use the simplistic hard-
coding technique we used earlier. Further, giving a
simple report name will not be sufficient for the
end-user reports – we need a way to specify folder
names too. Fortunately, there is a component
which will give us a nice “bird’s eye view” of all
reports on the server, without forcing us to hard-
code anything: the ClientReportExplorer.
rsClientReportExplorer1.Execute;
Publishing Reports to the Web
SERVER FUNDAMENTALS 17
Publishing Reports to the Web
The Server Edition has a special component, called The WebCachePath is the URI to the cache direc-
the WebTier, which converts the information pro- tory. We will create a virtual directory on the
vided by the server into an HTML/JavaScript server which maps to the CacheDirectory on the
application. Let’s configure a web tier and get a PC. The virtual directory describes a path which
feel for how it works. We’ll assume that our web will be accessible from a web browser (i.e. you can
tier will reside on a PC running IIS, and that we type it as an address in a web browser and the
will deploy the web application as an ISAPI DLL. server will return the content of the directory.)
First we create a new Web Server application from The WebModuleURI is an HTTP address which
within Delphi. To do this, select File | New | describes the exact location of the web tier on the
Other... and then select Web Server Application. server. This is the address you type into the
This will create a WebModule, which is a special browser to invoke the web tier.
kind of data module that knows how to talk to an
Next we need to process the requests received from
IIS web server. In the web module we place a
web browsers. To do this, we need to hook the
WebTier component.
Web Module to the Web Tier:
Assuming the web server is running on the same The web tier handles all possible requests through
machine as the report server application, we set the the method: ProcessWebRequest, and so we pass
following three property values: http requests straight through to the web tier, which
in turn provides the appropriate response. For more
CacheDirectory C:\myWebTier\Cache\
ServerConnection {use the default values}
on Web Modules and Actions, see the Delphi help.
WebCachePath http://localhost/myWebTier/Cache/
WebModuleURI http://localhost/myWebTier/myWebTier.dll We can now compile myWebTier and copy the
resulting DLL to C:\myWebTier. That’s all there is
The CacheDirectory names the system directory
to it!
where the WebTier will store the output generated
for a given session (folder/tree structures, page
object files, and images.)
Publishing Reports to the Web
18 SERVER FUNDAMENTALS
We may be done generating the DLL, but IIS isn’t If we’ve configured everything properly, you
yet configured to use it. We need to create a virtual should see the HTML version of the report
directory, so that IIS can make our new DLL avail- explorer in your web browser. Click on a report
able from a web browser. To do this: and the HTML version of the report viewer should
be displayed.
1 Select Start | Control Panel and double-click
Administrative Tools.
http://localhost/myWebTier/myWebTier.dll
Making Web Browser Content Printable With PDF
SERVER FUNDAMENTALS 19
Making Web Browser Content Printable With PDF
If you’re previewing a report in the browser, how
do you print it? Well, we can certainly right-click
over the frame which contains the page, select
Print and we will get “something.” But honestly,
HTML just doesn’t print very well. To get the
high-quality output we normally expect from
ReportBuilder, we’ll need to harness yet another
“web technology,” PDF and the Acrobat Reader.
ReportBuilder rsWebAdapaterPDF
Gnostice rsWebAdapaterPDFGnostice
Pragnaan rsWebAdapaterPDFPragnaan
Waler rsWebAdapaterPDFWaler
The text in the outline is all garbled. In the WebTier Cache directory, none of the
This is simply due to how your browser wraps text. sessions are ever deleted.
Resizing the outline frame should fix the problem. Session folders should be deleted when the session
timeout (WebTier.SessionOptions.SessionTime-
out) is exceeded (i.e. no activity for the session has
When I execute a new report, some of my old
reports are wiped from the cache. occurred in the last five minutes.) However, the
The web tier has a setting which determines the WebTier.dll must have read/write access to the
maximum number of reports which could be cache directory. The WebTier.dll runs under the
present in the cache simultaneously per session account IWAM_<MachineName>. Right-click
(SessionOptions.MaxReportCount). When the over the cache directory, access Properties... and
specified number of reports in the cache has been click the Security tab. Select IWAM_<Machine-
reached, the next incoming request from the same User> and give this user Full Control.
session will cause the least recently viewed report
be wiped from cache.
Proper use of the Volume.PublishingOptions Can I hot-swap reports running on the server?
should prevent runaway reports. However, in the Yes. The Report Server can dynamically discover
event of a runaway report, you will need to stop the the existence of new folders, reports, and archives.
service or (if you are running the server in stand- Thus you can add or replace reports and archives
alone mode) shut down the server application. A that are stored in files or a database. Of course
future version of the Server Edition may contain an changing reports which are compiled directly into
administrative application where you can stop indi- the server application requires that the server be
vidual sessions – but for now we are focused on stopped and replaced with a new executable con-
solidifying a fast, stable and scalable core. taining the new reports. That is why the Templat-
eVolume, ArchiveVolume, and ExplorerVolume
components are preferred - they specify a location
What happens if the server crashes?
where reports are stored.
When configured correctly, the server will simply
clean up after itself and automatically restart. This
is why you should deploy your server application Can I administer the server remotely?
using the Windows Service scheme. Under this Yes, using Windows remote desktop or a product
scheme if the server crashes, the Windows Service such as PCAnyWhere, you can run the RB Ser-
can automatically restart the application. The vices Manager. The RB Services Manager is avail-
server application is running in its own process able from the Start Menu, under ReportBuilder |
space – which means that other applications on the Services Manager. It is a system tray based appli-
same machine should not be affected if the server cation which allows you to start/stop the report
crashes. For reasons of both performance and sta- server or change the location of the server app (if
bility, you should also run your web tier as an Iso- you need to move the app to a different directory.)
lated Process. This keeps other ISAPI DLLs on The RB Services Manager is available only when
your web server from crashing your web tier and the server is deployed as a Windows Service.
vice versa. Of course, when a crash does occur, the
exception will be logged – so you should be able to
isolate the report causing the problem.
…RBServer\Tutorials\Server Projects
\01. Form-Based Report Application
initialization
TrsReportCatalog.RegisterReport(‘Examples',
5 Add an rsServer component to the form. ‘CustomerList',
‘ppReport1’,
Tfrm001CustomerList);
11 Close the Form and the associated unit, saving 4 Place a TDatabase component on the
all changes.
form.
9 Select the TDatabase and TSession components 3 Name the form’s unit frmThinClient and save it
and copy them to the clipboard. in the directory with the Server application.
10 Close the form saving all changes. 4 Name the project rbThinClient and save it in the
same directory.
11 Open each of the following forms, and paste the
Database and Session components into them. 5 Select the RBServer tab of the Component
Palette.
rb002Biolife
rb003OrderList
6 Place a rsClientReport component on the
rb004Sections
form.
rb005CustomerOrderItem
12 Select File | Close All from the Delphi menu, 7 Place a rsClientReportExplorer component
saving all changes. on the form.
Run the Server Application 8 Set the ClientReport property to
1 From the Windows desktop, launch a Windows “ClientReport1.”
Explorer.
9 Code the OnCreate event of the form as:
2 Locate the rbServer.exe in the directory you cre-
rsClientReportExplorer1.Execute;
ated for this tutorial.
3 Double-click the EXE to launch the applica- 10 Select File | Save All from the Delphi menu.
tion. 11 Run the application. You should see the Report
Explorer with all of the registered reports in the
“Examples” folder. You should be able to preview
the reports.
• Use Delphi Event Handlers with Server-based 3 Copy all of the files in:
Reports
…RBuilder\Tutorials\Server Projects\02.
File-Based Report Application
2 Add an rsReportTemplateVolume compo- 6 Click the dmMain tab of the Code Editor and
paste the code into the implemementation section
nent to the data module.
of the data module.
3 Set the FileDirectory property to:
7 Scroll to the first method in the data module and
C:\My RB Tutorials\02. File-Based Report place the cursor directly in front of TfrmMain class
Server
name.
4 Set the VolumeName to “Examples.” 8 Press Ctrl-R; the Replace Text dialog is dis-
5 Press Ctrl-S to save all changes. played.
Create a Thin-Client Application 11 Run the application. You should see the Report
1 Select File | New | Application from the Delphi Explorer with all of the registered reports in the
menu. “Examples” folder. You should be able to preview
the reports.
2 Select File | SaveProject As... from the Delphi
menu.
rsClientReportExplorer1.Execute;
7 Select the Table1 component and set Active to 8 Set the AutoSessionName property of the Ses-
True. This tests the new database path setting. sion component to True.
8 Run the project. You should see a single menu 9 Press Ctrl-S to save all changes.
item named “Reports.” Under this menu there
Register the Databased Reports
should be five reports listed. You should be able to
1 Select the RBServer tab of the Component
preview any of these reports.
Palette.
DataPipeline ppDBPipeline1
9 Close the application and return to the BLOBField Template
Delphi IDE. NameField Name
{rb005CustomerOrderItem}
procedure varItemTotalCalc(Sender: TObject; var Value: Variant);
procedure varOrderTotalCalc(Sender: TObject; var Value: Variant);
procedure ppDetailBand1BeforePrint(Sender: TObject);
rsServer1.Active := True;
rsClientReportExplorer1.Execute;
6 Copy the path from the Address box of the Win- 4 Select all of the components in the groups
dows Explorer. labeled Folders, Items, and Databases.
Deleted Deleted
FolderId FolderId
ItemId ItemId
ItemType ItemType
Name Name
Size Size
Template Template
7 Close the data module and the associated unit, 9 Shut-down the application.
saving all changes.
10 Select File | Close All from the Delphi menu,
Convert the Application to a Server saving all changes.
1 Select View | Project Manager from the Delphi
Run the Server Application
menu.
1 From the Windows desktop, launch a Windows
2 Double-click rbMain to display the form. Explorer.
3 Change the Caption of the form to: 2 Locate the rbServer.exe in the directory you cre-
Explorer Database Report Server ated for this tutorial.
4 Delete all of the components from the form. The 3 Double-click the EXE to launch the app.
form should now be blank. 4 Minimize the app.
5 Select the RBServer tab of the Delphi compo-
Create a Thin-Client Application
nent palette. 1 Select File | New | Application from the Delphi
menu.
6 Add a rsServer component to the form.
2 Select File | Save Project As... from the Delphi
7 Code the OnCreate event handler of the form as: menu.
rsServer1.Active := True;
3 Name the form’s unit frmThinClient and save it
Delete the event handler for the “Launch” button. in the directory with the Server application.
44 Building a Report Server Application for an Explorer Database
TUTORIALS
rsClientReportExplorer1.Execute;
…RBuilder\Tutorials\Server Projects\05.
Archive Report Application
Register the Report Archives 5 Remove all of the event handlers associated
1 Select File | New | Data Module from the Delphi with the Menu from the form’s unit.
menu.
2 Double-click rbMain to display the form. 8 Code the OnCreate event of the form as:
rsServer1.Active := True;
3 Change the Caption of the form to:
9 Run the application. It should compile and run
Archive Report Server
with no errors.
4 Delete the Menu and Archive Reader compo-
10 Shut-down the application.
nents from the form. The form should now be
blank. 11 Select File | Close All from the Delphi menu,
saving all changes.
rsClientReportExplorer1.Execute;
5 In the interface section add “rsServerActiveX” 3 Click the Change button and designate the
to the uses clause. rbServer application in:
6 Select Run | Parameters from the Delphi menu. C:\My RB Tutorials\06. Windows
Service-Based Server
7 In the parameters edit box enter:
4 Click the Start button. The top area of the dialog
/regserver should turn light green, indicating the server is
running.
8 Click OK to close the dialog.
5 Close the dialog.
9 Press F9 to run the project. If the COM server is
registered successfully, no message will be dis- Run the Thin-Client Application
played. 1 Return to the Delphi IDE.
Update the File Directory of the 2 Select File | Open Project from the Delphi
Report Volume Menu.
1 Select View | Project Manager from the Delphi
3 Locate rbThinClient.dpr in the directory for this
menu.
tutorial and open it.
2 Double-click dmMain to display the data
module.
For this tutorial, you will need a machine with IIS 3 Select the “Cache” directory.
5 installed. You will also need a report server 4 Right-click and select Properties.
application running. Therefore, completing the pre-
5 If you see the Securities tab, select this tab and
vious tutorial is recommended before beginning
continue with steps 6-8. If you do not see the Secu-
this tutorial.
rities tab, jump to the next section entitled “Create
Note: This tutorial was created using IIS 5, how- a Virtual Director on IIS.”
ever the steps for IIS 4 are similar. Depending on
6 Select IWAM_<MachineName> user.
your knowledge of IIS, you may be able to suc-
cessfully use this tutorial with IIS 4. 7 Click the “Full Control”checkbox.
Create a Virtual Directory on IIS 12 Click Finish. A new virtual directory will be
1 Access the Control Panel and double-click created and selected.
Administrative Tools.
13 Right-click over the new directory and select
2 Double-click Internet Information Services. Properties.
3 Expand “local computer,” “Web Sites” and 14 Locate the “Application Protection” drop-down
locate the “Default Web Site” entry. list at the bottom of the dialog.
5 Click Next.
11 Click Next.
Publish Reports to the Web
TUTORIALS
55
3 Scroll to the bottom row of icons and double- 11 Select the RBServer tab on the Delphi compo-
click “Web Server Application.” nent palette.
13 Configure as follows:
http://localhost/myWebTier/myWebTier.dll
56 Publish Reports to the Web
TUTORIALS
rbServer.exe
rb001CustomerList.raf
rb002Biolife.raf
rb003OrderList.raf
rb004Sections.raf
rb005CustomerOrderItem.raf
58 Scaling the Web Tier with a Server Farm
TUTORIALS
4 Paste these files into a network folder which is 7 Double-click this icon, to display the Report-
accessible from the two report server machines. Builder Services dialog.
5 Copy RBWinService.exe and ReadMe.doc 8 Click the Stop button to stop the sample server.
from:
9 Click the Change button and select rbServer.exe
C:\Program Files\Borland\Delphi6- in C:\Report Server.
\RBServer\Windows Service
10 Click the Start button; the top section of the dia-
To the same network folder in which you saved the
log should turn green after a second or two, indi-
report server application files.
cating that the server is running.
Deploy the Report Server Application
11 Close the dialog.
1 Move to the first report server machine. (You’ll
need to be at the keyboard for this computer.) 12 From the Windows Desktop select Start | Pro-
grams | Accessories | Command Prompt.
2 From the Windows Desktop launch a Windows
Explorer. 13 At the command prompt, type “ipconfig” and
press enter.
3 Create the directory:
14 Write down the IP address of the machine.
C:\Report Server
4 Copy the following files from the network 15 Repeat steps 1-14 on the second report server
folder into this directory: machine. You should now have two active report
server machines and the IP address of each.
rbServer.exe
rb001CustomerList.raf Check Each Server via Thin Client
rb002Biolife.raf 1 Return to the Web Server machine.
rb003OrderList.raf 2 From Delphi, open the project in:
rb004Sections.raf
C:\Program Files\Borland\Delphi6-
rb005CustomerOrderItem.raf
\RBServer\Demos\Clients-
\01. Client Explorer
5 Locate RBWinService.exe in the network
folder. 3 Select the “cbxAddress” combo box.
6 Run this program, accepting the default entries 4 Use the Object Inspector to enter the two IP
(this will install the Windows service that hosts the addresses for the server machines in the Items
report server application.) After the installation is property.
complete, you should see a new icon on your Sys-
5 Press Ctrl-S to save your changes.
tem Tray:
6 Run the application.
5 Return to Delphi and reopen the “myWebTier” 8 Experiment with creating load on a given server
project. and then launching a new web browser to see if the
other server is used. You should be able to get
6 Select the WebTier component and expand the
browsers with reports generated by both servers.
ServerFarmSettings property.