Creating the Web Service Proxy
A client and a Web service can communicate using SOAP messages, which encapsulate the input and output parameters as XML. A proxy class maps parameters to XML elements and then sends the SOAP messages over a network. In this way, the proxy class frees you from having to communicate with the Web service at the SOAP level and allows you to invoke Web service methods in any development environment that supports SOAP and Web service proxies.
There are two ways to add a proxy class to your development project using the Microsoft .NET Framework: with the WSDL tool in the .NET Framework, and by adding a Web reference in Microsoft Visual Studio. The following sections discuss this subject in further detail.
Adding the Proxy Using the WSDL Tool
The .NET Framework SDK includes the Web Services Description Language tool (Wsdl.exe), which enables you to generate a Web service proxy for use in the .NET Framework development environment. The most common way to create a client proxy in languages that support Web services (currently C# and Microsoft Visual Basic) is to use the WSDL tool.
To add a proxy class to your project using Wsdl.exe
From a command prompt, use Wsdl.exe to create a proxy class, specifying (at a minimum) the URL to the Report Server Web service.
For example, the following command prompt statement specifies a URL for the management endpoint of the Report Server Web service:
wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2010" https://<Server Name>/reportserver/reportservice2010.asmx?wsdl
The WSDL tool accepts a number of command-prompt arguments for generating a proxy. The preceding example specifies the language C#, a suggested namespace to use in the proxy (to prevent name collision if using more than one Web service endpoint), and generates a C# file called ReportingService2010.cs. If the example had specified Visual Basic, the example would have generated a proxy file with the name ReportingService2010.vb. This file is created in the directory from which you run the command.
Compile the proxy class into an assembly file (with the extension .dll) and reference it in your project, or add the class as a project item.
When you add a proxy class to your project manually, you need to add a reference to System.Web.Services.dll. If you add the proxy using a Web reference in Visual Studio .NET, the reference is automatically created for you. For more information, see "Adding the Proxy Using a Web Reference in Visual Studio" later in this topic.
After you add the proxy class as an item to your project, the associated file appears in Solution Explorer.
To call the service programmatically, create an instance of the proxy class.
The following code example shows the syntax for creating an instance of the ReportingService2010 proxy class in a project:
Dim service As New ReportingService2010()
ReportingService2010 service = new ReportingService2010();
For more information about the Wsdl.exe tool, including its full syntax, see "Web Services Description Language Tool" in the .NET Framework SDK documentation. For a full explanation of Web service proxies, see "Creating an XML Web Service Proxy" in the .NET Framework SDK documentation.
Adding the Proxy Using a Web Reference in Visual Studio
A Web reference enables a project to consume one or more Web services. Visual Studio enables users to add Web service references to projects by following a few simple steps.
To add a Web reference to a project
In Solution Explorer, select the project that will consume the Web service.
On the Project menu, click Add Web Reference.
The Add Web Reference dialog box opens.
In the URL field, enter the complete path to the Report Server Web service.
A simplified URL for the report execution endpoint of the Report Server Web service might look like this:
The URL contains the domain in which the Report Server Web service is deployed, the name of the folder containing the service, and the name of the discovery file for the service. For a complete description of the different URL elements, see Accessing the SOAP API.
A description of the methods and properties provided by the Web service appears in the Browser pane on the left.
For more information about the items associated with the Report Server Web service, see Report Server Web Service Methods.
Verify that your project can use the Report Server Web service, and that you have appropriate permission to access the report server.
In the Web reference name field, enter a name that you will use in your code to access the Report Server Web service programmatically.
Select the Add Reference button to create a reference in your application to the Web service.
The new reference appears in Solution Explorer under the Web References node for the active project, named as specified in the Web reference name field.
In Solution Explorer, expand the Web References folder to note the namespace for the Web reference classes that are available to the items in your project.
After adding a Web reference to your project, the associated files are displayed in a folder within the Web References folder of Solution Explorer.
After you add the Web reference, use the following syntax to create an instance of the proxy class:
Dim rs As New myNamespace.myReferenceName.ReportExecutionService() rs.Url = "https://<Server Name>/reportserver/reportexecution2005.asmx?wsdl" rs.Credentials = System.Net.CredentialCache.DefaultCredentials
myNamespace.myReferenceName.ReportExecutionService rs = new myNamespace.myReferenceName.ReportExecutionService(); rs.Url = "https://<Server Name>/reportserver/reportexecution2005.asmx?wsdl"; rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
You can also add a using (Import in Visual Basic) directive to the Report Server Web service reference. 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 your file: