Add, update, or remove a WCF data service reference

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.

For .NET Core projects, you can use the Connected Services node in Solution Explorer to access the Microsoft WCF Web Service Reference Provider, which lets you manage Windows Communication Foundation (WCF) data service references.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in this article. You might 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 might 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 might 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 an external service (.NET Core projects, including .NET 5 and later)

  1. In Solution Explorer, double-click or tap the Connected Services node.

    The Configure Services tab opens.

  2. Choose Microsoft WCF Web Service Reference Provider.

    The Configure WCF Web Service Reference dialog appears.

    Screenshot of WCF Web Service Provider dialog box

  3. In the URI 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 might be prompted for a user name and password.

    Note

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

    You can also select the URL from the URI 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.

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

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

  6. Click Finish 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.

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

  1. In Solution Explorer, double-click or tap the Connected Services node.

    The Configure Services tab opens.

  2. Choose Microsoft WCF Web Service Reference Provider.

    The Configure WCF Web Service Reference dialog appears.

  3. Click Discover.

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

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

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

  6. Click Finish 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

  • In Solution Explorer, right-click the service reference and then click Update Service Reference.

    A progress dialog box displays while the reference is updated from its original location, and the service client is regenerated to reflect any changes in the metadata.

  • In Solution Explorer, expand the Connected Services node, right-click the service reference, and then click Update Service Reference.

    A progress dialog box displays while the reference is updated from its original location, and the service client is regenerated to reflect any changes in the metadata.

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.