How to: Add, update, or remove a WCF data service reference

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

For .NET Framework projects, service reference enables a project to access one or more WCF Data Services. Use the Add Service Reference dialog box to search for WCF Data Services in the current solution, locally, on a local area network, or on the Internet.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in this article. You may be using a different edition of Visual Studio or different environment settings. For more information, see Personalize the IDE.

Prerequisites

The WCF tools are not installed with the .NET workload; use the Visual Studio Installer to modify your installation. In the installer, choose Windows Communication Foundation under Individual Components. See Modify Visual Studio.

Add a WCF service reference

To add a reference to an external service (.NET Framework projects)

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

    The Add Service Reference dialog box appears.

  2. In the Address box, enter the URL for the service, and then click Go to search for the service. If the service implements user name and password security, you may be prompted for a user name and password. You can also choose a service in your own solution. Choose the Discover button, and then choose Services in Solution.

    Note

    You should only reference services from a trusted source. Adding references from an untrusted source may compromise security.

    You can also select the URL from the Address list, which stores the previous 15 URLs at which valid service metadata was found.

    A progress bar displays when the search is being performed. You can stop the search at any time by clicking Stop.

  3. In the Services list, expand the node for the service that you want to use and select an entity set.

  4. In the Namespace box, enter the namespace that you want to use for the reference.

  5. Click OK to add the reference to the project.

    A service client (proxy) is generated, and metadata that describes the service is added to the app.config file.

To add a reference to a service in the current solution (.NET Framework projects)

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

    The Add Service Reference dialog box appears.

  2. Click Discover.

    All services (both WCF Data Services and WCF services) in the current solution are added to the Services list.

  3. In the Services list, expand the node for the service that you want to use and select an entity set.

  4. In the Namespace box, enter the namespace that you want to use for the reference.

  5. Click OK to add the reference to the project.

    A service client (proxy) generates, and metadata that describes the service is added to the app.config file.

Update a service reference

The Entity Data Model for a WCF Data Services sometimes changes. When this happens, you must update the service reference.

To update a service reference

Remove a service reference

If a service reference is no longer being used, you can remove it from your solution.

To remove a service reference

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

    The service client will be removed from the solution, and the metadata that describes the service will be removed from the app.config file.

    Note

    Any code that references the service reference must be removed manually.

See also