Lesson 3: Accessing the Web Service


Applies To: SQL Server 2016

After you add a reference for the Report Server Web service to your project, the next step is to create an instance of the Web service's proxy class. You can then access the methods of the Web service by calling the methods in the proxy class. When your application calls these methods, the proxy class code generated by Visual Studio handles the communications between your application and the Web service.

First, you will create an instance of the Web service's proxy class, ReportingService2010. Next, you will make a call to the Web service's ReportingService2010.getproperties method using the proxy class ReportingService2010.GetProperties Method (String, Property()). You will use the call to retrieve the name and description of one of the sample reports, Company Sales.

System_CAPS_ICON_note.jpg Note

When accessing a Web service running on SQL Server Express with Advanced Services, you must append "$SQLExpress" to the "ReportServer" path. For example:

http://<Server Name>/reportserver$sqlexpress/reportservice2010.asmx"

To access the Web service

  1. You must first add the namespace to the Program.cs file (Module1.vb in Visual Basic) by adding a using (Imports in Visual Basic) directive to the code file. If you use this directive, you do not need to fully qualify the types in the namespace.

  2. To do this, add the following code to the beginning of your code file:

    using System;
    using GetPropertiesSample.ReportService2010;
  3. Once you have entered the namespace directive to your code file, enter the following code in the Main method of your console application. Make sure to change the name of your server when setting the Url property of the web service instance:

    static void Main(string[] args)
       ReportingService2010 rs = new ReportingService2010();
       rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
       rs.Url = "http://<Server Name>/reportserver/reportservice2010.asmx";
       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(
          "/AdventureWorks 2012 Sample Reports/Company Sales 2012",properties);
          foreach (Property p in returnProperties)
             Console.WriteLine(p.Name + ": " + p.Value);
       catch (Exception e)
  4. Save the solution.

The walkthrough sample code uses the ReportingService2010.getproperties method of the Web service to retrieve properties of the sample report, Company Sales 2012 ReportingService2010.GetProperties Method (String, Property()). The method takes two arguments: the name of the report for which you want to retrieve property information and an array of Property[] objects that contains the names of properties whose values you want to retrieve. The method also returns an array of Property[] objects that contains the names and values of the properties specified in the properties argument.

System_CAPS_ICON_note.jpg Note

If you supply an empty Property[] array for the properties argument, all available properties are returned.

In the previous sample, the code uses the ReportingService2010.getproperties method to return the name and description of the sample report, Company Sales 2012. The code then uses a foreach loop to write the properties and values to the console.

For more information about creating and using a proxy class for the Report Server Web service, see Creating the Web Service Proxy.

Lesson 4: Running the Application (VB - VC#)
Accessing the Report Server Web Service Using Visual Basic or Visual C# (SSRS Tutorial)

Community Additions