Export (0) Print
Expand All

Walkthrough – Accessing the Reporting Services Web Service Using Visual Basic or Visual C#

SQL Server 2000

The following walkthrough describes the process for accessing the Reporting Services Web service from an application created with Visual Basic or Visual C#.

During the course of this walkthrough, you will accomplish the following activities:

  • Create a client application using the Visual Studio .NET Console Application project template.
  • Add a Web reference for the Reporting Services Web service.
  • Write code to access the Web service.
  • Run the console application in debug mode.

Requirements

To complete the walkthrough, you must have the following:

  • Microsoft® SQL Server™ 2000 Reporting Services
  • Microsoft Visual Studio® .NET 2003 or a similar .NET Framework compatible development tool.
  • Sufficient permissions to be able to access the Reporting Services Web service on the computer where your report server is.
  • A report installed on your report server. This walkthrough assumes the sample report, Company Sales. For more information, see Reporting Services Sample Reports.

Creating the Web Service Client Project

For this walkthrough, you will create a simple console application that accesses the Reporting Services Web service. This walkthrough assumes you are developing in Microsoft Visual Studio .NET.

To create a console application

  1. On the File menu, point to New, and then click Project to open the New Project dialog box.
  2. Expand either the Visual Basic Projects or the Visual C# Projects folder.
  3. Click the Console Application icon.
  4. In the Name box, enter a name for your project. Enter the name, GetPropertiesSample.
  5. In the Location box, enter the path where you want to save your project, or click Browse to navigate to the folder.
  6. Click Open. A collapsed view of your project appears in Project Explorer.

    In Project Explorer, expand the project node. A file with the default name of Class1.cs (Module1.vb for Visual Basic) has been added to your project.

Adding a Web Reference

Web service discovery is the process by which a client locates a Web service and obtains its service description. The process of Web service discovery in Visual Studio involves interrogating a Web site following a predetermined algorithm. The goal of the process is to locate the service description, which is an XML document that uses the Web Services Description Language (WSDL).

The service description describes what services are available and how to interact with those services. Without a service description, it is impossible to programmatically interact with a Web service.

Your application must have a means to communicate with the Web service and to locate it at run time. Adding a Web reference to your project for the Web service does this by generating a proxy class that interfaces with the Web service and provides a local representation of the Web service. For more information, see "Web References and Generating an XML Web Service Proxy" in your Visual Studio .NET documentation.

To add a Web reference

  1. On the Project menu, click Add Web Reference.
  2. In the URL box of the Add Web Reference dialog box, type the URL to obtain the service description of the Reporting Services Web service, such as http://localhost/reportserver/reportservice.asmx?wsdl. Then click the Go button to retrieve information about the Web service.

    - or -

    If the Reporting Services Web service exists on the local machine, click the Web services on the local machine link in the browser pane. Then click the link for the ReportService Web service from the list provided.

  3. In the Web reference name box, rename the Web reference to ReportingServices, which is the namespace you will use for this Web reference.
  4. Click Add Reference to add a Web reference for the target Web service.

    Visual Studio downloads the service description and generates a proxy class to interface between your application and the Reporting Services Web service.

For more information, see Accessing the SOAP API.

Accessing the Web Service

Once you add a reference for the 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 in the same manner that you access any object's methods by calling 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, ReportingService. Next, you will make a call to the Web service's GetProperties method using the proxy class. You will use the call to retrieve the name and description of one of the sample reports, Company Sales.

To access the Web service

  1. You must first add the namespace to the Class1.cs file (Module1.vb in Visual Basic). You accomplish this by adding a using (Import 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. To do this, add the following code to the beginning of your code file:

Imports System
Imports GetPropertiesSample.ReportingServices

using System;
using GetPropertiesSample.ReportingServices;
  1. Once you have entered the namespace directive to your code file, enter the following code in the Main method of your console application:

Sub Main()
   Dim rs As New ReportingService
   rs.Credentials = System.Net.CredentialCache.DefaultCredentials

   Dim name As New [Property]
   name.Name = "Name"

   Dim description As New [Property]
   description.Name = "Description"

   Dim properties(1) As [Property]
   properties(0) = name
   properties(1) = description

   Try
      Dim returnProperties As [Property]() = rs.GetProperties("/SampleReports/Company Sales", properties)

      Dim p As [Property]
      For Each p In returnProperties
          Console.WriteLine((p.Name + ": " + p.Value))
      Next p

   Catch e As Exception
      Console.WriteLine(e.Message)
   End Try
End Sub

static void Main(string[] args)
{
   ReportingService rs = new ReportingService();
   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;

   try
   {
      Property[] returnProperties = rs.GetProperties("/SampleReports/Company Sales", properties);
   
      foreach (Property p in returnProperties)
      {
         Console.WriteLine(p.Name + ": " + p.Value);
      }
   }

   catch (Exception e)
   {
      Console.WriteLine(e.Message);
   }
}
  1. Save the solution.

The walkthrough sample code uses the GetProperties method of the Web service to retrieve properties of the sample report, Company Sales. The GetProperties 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.

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 GetProperties method to return the name and description of the sample report, Company Sales. 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 Reporting Services Web service, see Creating the Web Service Proxy.

Running the Application

Visual Studio offers several methods to build and run a console application from the IDE, such as:

  • Start (with Debugging)
  • Start without Debugging

To build and run the GetPropertiesSample

  1. From the Debug menu, click Start Without Debugging. This ensures that the console window remains open after the program has finished executing.

    The application prints the following output to the console:

    Name: Company Sales
    Description: Adventure Works sales by quarter and product category. This report
    illustrates the use of a matrix data region that provides drilldown from summary
    data into detail data by showing and hiding rows. This report also illustrates
    the use of background images.
    Press any key to continue
    
  2. Press any key to close GetPropertiesSample.
See Also

ReportingService.GetProperties Method

Property Class

Reporting Services Samples and Walkthoughs

Walkthroughs

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft