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 the 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® .NET. The following sections discuss this subject in further detail.
Adding the Proxy Using the WSDL Tool
The Microsoft .NET Framework SDK includes the Web Services Description Language tool (Wsdl.exe), a utility that you can use to generate a Web service proxy for use in the.NET Framework development environment. The most common way to create a client proxy in any of the .NET languages that support Web services (currently C# and Visual Basic® .NET) 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 Reporting Services Web service.
For example, the following command prompt statement specifies a URL:
wsdl /language:CS http://myserver/reportserver/reportservice.asmx
The WSDL tool accepts a number of command-prompt arguments for generating a proxy. The preceding example specifies the .NET language C# and generates a C# file called ReportingService.cs. If the example had specified Visual Basic, the example would have generated a proxy file with the name ReportingService.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.
Note 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 .NET" 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 ReportingService proxy class in a project:
For more information about the Wsdl.exe tool, including its full syntax, see "Web Services Description Language Tool" in the Microsoft .NET Framework SDK documentation. For a full explanation of Web service proxies, see "Creating an XML Web Service Proxy" in the Microsoft .NET Framework SDK documentation.
Adding the Proxy Using a Web Reference in Visual Studio .NET
A Web reference enables a project to consume one or more Web services. Visual Studio .NET 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 Reporting Services Web service.
A simplified URL for the Reporting Services Web service might look like this:
The URL contains the domain in which the Reporting Services 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.
Note For more information about the items associated with the Reporting Services Web service, see Web Service Features.
- Verify that your project can use the Reporting Services Web service, and that you have appropriate permission to access the report server.
Security Note When you open a project for editing that includes a Web reference, a local proxy file for the Web service consumed runs in a process of devenv.exe started by a trusted user: yourself. Opening projects or components in the integrated development environment (IDE) can execute code on your local machine.
- In the Web reference name field, enter a name that you will use in your code to access the Reporting Services 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:
You can also add a using (Import in Visual Basic) directive to the Reporting Services 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: