How to use WCF DS 5.0 in a Web Site project

DB Blogs

The WCF Data Services 5.0 RTM release includes an update to the Add Service Reference behavior in Visual Studio. For most project types that target .NET Framework 4.0, this means that when you add a new service reference, you will automatically get assembly references to the new client assemblies, and your client will be able to communicate with servers that support v3 of the OData protocol.

This does not happen by default for Web Site Projects, but there are some manual steps you can take to update these projects to use the new functionality. This applies to Web Site Projects only, not Web Application Projects or any other type of project with support for WCF Data Services.

Configuring a Web Site Project to work with WCF Data Services 5.0:

  1. Add a Service Reference in the Web Site project.

    How to: Add, Update, or Remove a Service Reference

    This will add the service reference with assembly references to the WCF Data Services client that is included with .NET Framework 4.0, and not the updated version that is included with the 5.0 RTM release.

  2. Update the project’s assembly references to point to the new client.

    There are three ways to do this:

    • (Recommended) Use NuGet to install the Microsoft.Data.Services.Client package. Click the Tools menu, then Library Package Manager, then Package Manager Console. In the console, type Install-Package Microsoft.Data.Services.Client. You will still need to remove the reference to System.Data.Services.Client using one of the methods below.

    • Right-click the project name in Solution Explorer, select Property Pages, then choose the References tab. Remove the reference to System.Data.Services.Client, then add references to Microsoft.Data.Services.Client, Microsoft.Data.OData, Microsoft.Data.Edm and System.Spatial that were installed with WCF Data Services 5.0.

    • Edit the <assemblies> section in the project’s web.config file.

      Remove the reference to System.Data.Services.Client:

          <add assembly="System.Data.Services.Client, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

      Add references to the new client assemblies:

          <add assembly="System.Spatial, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add assembly="Microsoft.Data.Services.Client, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add assembly="Microsoft.Data.OData, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add assembly="Microsoft.Data.Edm, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  3. Configure the project to use the new build provider for WCF Data Services.

    Edit the web.config file to override the default DataServiceBuildProvider that is specified in the root web.config that is installed with the .NET Framework.

        <remove name="DataServiceBuildProvider"/>
        <add name="DataServiceBuildProvider" type="System.Data.Services.BuildProvider.DataServiceBuildProvider, Microsoft.Data.Services.Design, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

    This step only needs to be done once per project and does not need to be repeated if additional service references are added. All other steps need to be done for each service reference.

  4. Update the Reference.datasvcmap file for the service reference.

    The Reference.datasvcmap file contains parameters that control how the code is generated for the service reference. The following parameters are the default for other project types and will allow your types to be used with data binding and will allow the client to communicate with services that support v3 of the OData protocol.

        <Parameter Name="UseDataServiceCollection" Value="true" />
        <Parameter Name="Version" Value="3.0" />


Discussion is closed.

Feedback usabilla icon