Tuesday, January 29, 2008

WinForm Client for Reporting Server

Introduction
I started to play around with MS Reporting Server. Honestly speaking: I like it. It needs some minor enhancements, but overall it is a very nice product. You create your reports in minutes from within Visual Studio and deploy it to your IIS. The reports are immediatly visible for the audience (if they have the proper rights to access your IIS) and the reports look quite nice from the beginning (do not forget to add a footer with a page counter, today's date and maybe the user name to your reports so that also management likes them). Nice, but a web client alone is not what I was looking for. It is great for your end users, but as a developer I want a WinForm client.

The Winform Client requirements
With this client I wanted to be able to test my reports and use it as a little helper tool during development (check header, footer and the overall outcome of the reports).
  • connect to any reporting server
  • use default credentials or
  • pass a username and password combination
  • get the list of reports dynamically
  • I want to decide how many reports I would like to see
The implementation
It turned out that this is quite easy to implement.
The steps to reproduce are quite short:
  1. Create a new Winform application in Visual Studio.

  2. Place the following controls on the form:
    A Textbox for the server URL
    A Combobox used to populate with a list of available reports
    Two buttons - one to fill the combo and one to run the report
    A tab control with two pages and on both pages we need a ReportViewer control

Let's start coding
We need to create a web reference (right mouse button on References in solution explorer) which gives us a local proxy to the reporting server web service (the url for a local installation is http://localhost/reportserver/reportservice.asmx). I gave it the name RSWebService.

We need to instance variables to hold the web service proxy and the current ReportViewer control:

private ReportingService _rs = null;
private ReportViewer _currentViewer;

Also, a small helper class to hold the report name and report URL comes in handy:

The next thing we need to code is the button to connect to the web service using the proxy, retrieve a list of reports and fill the combobox. You see the full code below (click on the image to get it readable).

Now, our users would like to choose a report and show the report in the tab page.

Last but not least we would like to create a new tab page with a ReportViewer control on it if the user clicks on the last tab page on the tab control - which means we have to code the
SelectedIndexChanged event as you can see below.


Conclusion
Rporting server is really a cool piece of Microsoft SQL Server. With this small helper application development with it becomes even more fun and a bit easier (at least for me).

I hope you enjoyed this small article!







CSharpCodeFormatter