There are two types of WebServices, which Reporting Services provide. Their names are “ReportService2005.asmx” and “ReportExecution2005.asmx”.
“ReportService2005.asmx” provides a bunch of methods which can be called reporting service management API, while “ReportExecution2005.asmx” is intended to process and render reports on the report server.
Our product is intended for rendering Reporting Services server reports and displaying them in our Silverlight Viewer. It sounds reasonable to use “ReportExecution2005.asmx” for that purposes, but sometimes we need something more and we can’t do that with “ReportExecution2005.asmx”. In this article I will show you how to make our product and Reporting Services Management API friends. The main idea of this example is that we will have a list of reports from the specified virtual directory and after choosing one of them we will render the report in the Viewer. Our Viewer has no power to get list of reports and that is why we need Management API to get this list.
Let’s start with a sample which comes with our getting started:
Make sure that our sample works fine and then we may get to our current task.
Firstly, we will create service reference to the “ReportService2005.asmx”.
Ordinary Url of this webservice looks like: http://<servername>/reportserver_<sql instance name>/reportservice2005.asmx. Let’s call this service “ManagementAPI”. We need to get a List of reports from the specified directory and pass them to the client side. Let’s create WCFService for that purpose and call it ManagementBL.
Next method will be a service method and will provide a list of report names from the specified directory:
{
List result = new List();
ManagementAPI.ReportingService2005 managementService = new ManagementAPI.ReportingService2005();
managementService.Credentials = System.Net.CredentialCache.DefaultCredentials;
CatalogItem[] items = managementService.ListChildren(folderName, false);
foreach (CatalogItem item in items)
{
if (item.Type == ItemTypeEnum.Report)
{
result.Add(item.Path);
}
}
return result;
}
Then, on the client side, we will add service reference to our WCFService.
http://localhost:5555/ManagementBL.svc?wsdl
The namespace for this Service Reference will be “ManagementBLService”.
Let’s define rather simple layout for our page:
<Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition Height="20"/> </Grid.RowDefinitions> <reportviewer:ReportViewer x:Name="reportViewer" Grid.Row="0" /> <ListBox x:Name="listboxReports" Grid.Row="1"/> <Button x:Name="buttonRender" Grid.Row="2" Content="Render" Click="buttonRender_Click" /> </Grid>
In the code behind this page we will have
{
public MainPage()
{
InitializeComponent();
reportViewer.Loaded += new RoutedEventHandler(reportViewer_Loaded);
//create client for our service
ManagementBLService.ManagementBLClient client = new ManagementBLService.ManagementBLClient();
client.GetReportListCompleted += new EventHandler(client_GetReportListCompleted);
//asyncronous call of getting report list method
client.GetReportListAsync("/");
}
void client_GetReportListCompleted(object sender, ManagementBLService.GetReportListCompletedEventArgs e)
{
listboxReports.ItemsSource = e.Result;
}
private void reportViewer_Loaded(object sender, RoutedEventArgs e)
{
if (HtmlPage.IsEnabled == false)
{
reportViewer.ServiceUrl =
"http://localhost:5555/ReportService.svc";
}
else
{
SilverlightInitParamsHelper initParamsHelper = new SilverlightInitParamsHelper(HtmlPage.Plugin.GetProperty("initParams").ToString());
reportViewer.ServiceUrl = initParamsHelper.ServiceUrl;
}
reportViewer.ApplyTemplate();
}
private void buttonRender_Click(object sender, RoutedEventArgs e)
{
if (listboxReports.SelectedItem != null)
{
reportViewer.ReportName = (string)listboxReports.SelectedItem;
reportViewer.RenderDocument();
}
}
}
Here is the result of our manipulations:
You just need to choose a report from the listbox, push “Render” button to get your report being rendered in the report viewer.