Monday, April 05, 2010

Connecting to SSRS Web-Services from Visual Studio 2008

Or “How to add a web-service reference to a WinForm or a Console based application”.

Its easy to connect to the SSRS web-service from VS2005. Simply add a web-reference by right clicking on the references node and they enter the web-service end-point. (This is typically “http://serverName/ReportServer/ReportService2005.asmx” – note: the 2005 in the end is used even if you are attempting to connect to SSRS2008).

If you use the following code, it should all build correctly and also run.

SSRS.ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

Property name = new Property();
name.Name = "Name";

Property description = new Property();
description.Name = "Description";

Property[] properties = new Property[2];
properties[0] = name;
properties[1] = description;

    Property[] returnProperties = rs.GetProperties("/Reports/reportName", properties);

    foreach (Property p in returnProperties)
        Console.WriteLine(p.Name + ": " + p.Value);

catch (Exception e)

If you try to add a webservice reference is VS2008, all you get is an option to add a service reference and if you use the next dialog to connect to your SSRS webservice end-point, the sample code shown above will not compile. (you will get errors regarding no Credentials property available as well as a whole litany of others).

Instead here is what you need to do:

Click on the Add Service Reference Option.

Click on the Advanced Button.

The next dialog has the “Add Web Reference” button.

Enter the end-point address in the next dialog.

Now the code shown above should work.

So what is the difference between “Add Web Reference” and “Add Service Reference”? Turns out that you can use the Add Web Reference option only when you have a WSDL document. But if you need to use any WCF based service – not just WSDL based ones, you need to use the “Add Service Reference” option.

No comments: