Sdílet prostřednictvím


How to: Add and Remove Web References

Note

This topic pertains to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation.

A Web reference enables a project to consume one or more XML Web services. Use the Add Web Reference Dialog Box to search for Web services locally, on a local area network, or on the Internet.

After adding a Web reference to your current project, you can call any methods exposed by the Web service. For details, see How to: Call a Web Service.

For information about creating a Web service class, see Walkthrough: Building a Basic XML Web Service Using ASP.NET.

To add a Web reference to a project

  1. In Solution Explorer, right-click the name of the project to add the Web service to and then click Add Web Reference.

    The Add Web Reference dialog box is displayed.

  2. In the URL box, enter the URL of the Web service to use. If you do not know the URL, use the links in the browse pane to locate the Web service you want.

    Note

    If you are developing a Web application on a computer that is behind a firewall, and your application will consume Web services from outside the firewall, you must include the address and port of your network's proxy server in the URL. Ask your network administrator to furnish this part of the URL path. For more information, see "The proxy settings on this computer are not configured correctly for Web discovery" in the Visual Studio 2005 SDK.

  3. In the Web services found at this URL box, select the Web service to use.

  4. Verify that your project can use the Web service, and that any external code provided is trustworthy.

    Security noteSecurity 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 computer. For more information, see Overview of Web Application Security Threats and Code Access Security.

  5. In the Web reference name field, enter a name that you will use in your code to access the selected Web service programmatically.

    Note

    By default, Web references are assigned a namespace that corresponds to their server name. You can change this value and enter a custom namespace name. There are some limitations on acceptable namespace names. For more information about characters that are not allowed in a Web reference name, see Add Web Reference Dialog Box. Visual Web Developer creates a namespace based on the Web reference name by building a nested folder hierarchy. Inside the innermost folder, a .wsdl file that references the Web service is created, along with supporting files, such as discovery (.disco and .discomap) files, that include information about where the Web service is located.

  6. Click Add Reference.

    If your Web site does not already have one, Visual Studio creates an App_WebReferences folder. It then creates files required for the proxy class using the name you provided in Step 5.

Removing a Web Reference

If your project no longer needs a Web reference to an XML Web service, you can remove the reference from your project.

To remove a Web reference from a project

  • In Solution Explorer, right-click the Web reference and then click Delete.

    All the reference information is removed from the project and from local storage.

See Also

Tasks

How to: Call a Web Service

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

Other Resources

XML Web Services Overview

Walkthrough: Building a Basic XML Web Service Using ASP.NET