Managing Windows Azure Reporting Services

Windows Azure provides Reporting Services (SSRS) as a service. This allows you to take your SSRS report, upload to the portal, and start running the report for your users. I have blogged before about how to download a rendered report programmatically, but how do you upload the reports in the first place?

You can manually upload reports in the portal. However, there seems to be a small problem with this technique. You can create folders, and sub folders to hold your reports, but you can’t upload a report to a subfolder.

I set about attempting to upload reports from code. There’s no management API support for reports, instead you need to use the SSRS Web Service (using something called SOAP – consult your history books if you’re under the age of 60).

I had some problem (using WSDL in mono) creating the proxy, so for your convenience, here’s a proxy generated for you.

With the proxy referenced in your project, you’re good to go. Here’s how to log in to the service:

 

var serviceUsername = "your username";
var servicePassword = "your password";
var url = @"https://XXX.reporting.windows.net/reportserver/reportservice2010.asmx";
var client = new ReportingService2010
{
  Url = url,
  CookieContainer = new CookieContainer()
};
client.LogonUser(serviceUsername, servicePassword, url);

You’ve now got a logged in client for the web service, ready to manage reports.

 

First, let’s list the reports we’ve got:

 

var items = rs.ListChildren ("/", true);

This will list everything, data sources, folders and reports. To see just the reports, you can filter by the TypeName:

 

foreach (var child in children.Where(x => x.TypeName == "Folder"))
{
  Console.WriteLine(child.Path);
}

The ‘Path’ property is the full name of the report, including the path  representing the folder hierarchy.

Uploading a report is a bit more involved, so I’ll save you some time by giving you this extension method:

 

public static void DeployReport (this ReportingService2010 client, string reportFile, string parent = "/", string name = "new report")
{
  using (var stream = File.OpenRead(reportFile))
  {
    var definition = new Byte[stream.Length];
    stream.Read(definition, 0, (int)stream.Length);
  }
  Warning[] warnings = null;
  client.CreateCatalogItem("Report", name, parent, true, definition, null, out warnings);
  if (warnings != null)
  {
    foreach (var warning in warnings)
      Console.WriteLine(warning.Message);
  }
}

If you want to set the description of the report, just add a NameValueItem to the Properties argument. If the NameValueItem has a Name of  ‘Description’, the value will be added as the description of the report.

A report can be deleted like this:

 

client.DeleteItem(reportName);

Simple!

Advertisements