Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Collapse]Data Binding Common Concepts
    How to: Bind GridControl to Database and Implement Master-Detail Mode at Design Time
    How to: Bind a Control to a Database at Runtime
    How to: Bind a Control to Data Created at Runtime
    How to: Bind a Control to Data in an XML File
    Traditional Data Binding Methods
    Data Source Configuration Wizard
    Data Binding Mechanism in ADO.NET
    Binding Controls to XML Data
    Binding Controls to Data Created at Runtime
    Add Unbound Data to a Data-Aware Control (XtraGrid, XtraPivotGrid)
    Binding to Excel Data Sources
    Binding to LINQ to SQL Classes
    Unbound Sources
    Binding to Entity Framework Core
    Binding to OData
    Binding to SQL Data
    Data Annotation Attributes
    How to: Add Virtual Rows Using the UnboundSource Component
    Obtaining Fields Available in Data Source
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Binding to OData

OData V4 is an open protocol initiated by Microsoft. Its RESTful API allows you to publish, read and edit resources defined in a data model using simple HTTP messages. The protocol currently includes three major versions: 2.0, 3.0 and 4.0. This document spotlights versions 4.0 and 2.0 as the most widely used versions. For version 2.0, binding by using Windows Communication Foundation (WCF) services is used.

Expanded Prerequisites

For both v4 and v2 OData sources, start with the following.

  1. Create a new WinForms application and add a Data Grid (or any other DevExpress data-aware control) onto the form.
  2. Make sure the target .NET framework of your project is of version 4.5 or higher. To check and modify the target framework version, go to "Project | <Your_Project_Name> Properties", then use the "Target framework" editor to select a required version.

  3. Install the OData Client for .NET NuGet package. To do so, invoke the Package Manager Console as shown below.

    Run the following command to install the package.

    PM >  Install-Package Microsoft.OData.Client -Version 6.15.0

    OData v4 and OData v2 use different versions of this package, so you may need to upgrade or downgrade it. To do so, go to "Project | Manage NuGet Packages" and locate the installed package. Select it, then change its version in the package details page, as shown below.

After completing these steps you can proceed to binding your data-aware control to OData v4 or OData v2.

Expanded Binding To OData V4 Services Using the Wizard

This section is dedicated to binding DevExpress data-aware controls by utilizing the Data Source Configuration Wizard.

  1. Right click your project in Visual Studio and select "Add | New Item...", then switch to the "Online" tab. Find and install the "OData v4 Client Code Generator" item template.

    Note

    This step is required for your first OData v4 application only. Once this VS template has been installed, it will be available for all future projects.

  2. Invoke the wizard and select "OData V4 Services". Click the "New Data Source..." button and select the "OData Client" option, then click "Add" to proceed.

  3. After the new data source is ready, you will be taken to the .tt file with settings. In this file, locate the MetadataDocumentUri property and set it to a valid service document URI or a local file path. For testing purposes you can utilize any online sample service, e.g. "http://services.odata.org/V4/OData/OData.svc/" or TripPin Service.
  4. Rebuild the project, then invoke the Data Source Configuration Wizard again. This time, you will see your added Data Source in the list. Select it and click "Next".

  5. On the next Wizard page, you can select how exactly your data should be connected.

    • Direct Binding to Data Source - the data-aware control will bind directly to the data source, without any go-between components involved.
    • Binding via the BindingSource Component - a new System.Windows.Forms.BindingSource component will be spawned to transfer data to your data-aware control.
    • Asynchronous Server-Side Data Processing - data will be transfered by the ODataInstantFeedbackSource component.
    • Server-Side Data Processing - data will be transfered by the ODataServerModeSource component.

    Select a required connection mode and click "Next".

  6. The final Wizard page requires you to enter the data service root URL and a table from which to display data. For server and instant feedback modes, you can also choose a data field that serves as a key expression, and sort all data by another data field.

    When you enter the URL, click the "Test Connection" button. If its initial red glow is gone and the button becomes disabled, the connection was established successfully.

  7. After you have filled all required fields, press "Finish". Your data-aware control is now bound to Open Data.

Expanded Binding To OData V2 Services Using the Wizard

  1. Invoke the wizard and select "WCF Data Services". Click the "New Data Source..." button to create a new source or select an existing one from the list.

  2. In the "Add Service Reference" dialog that appears on screen, enter the OData service URL and click "Go" to establish a connection (try "http://services.odata.org/V2/Northwind/Northwind.svc/" for testing purposes). In case of a successful connection, you will see all available services in the "Services" list. Expand a service to browse its data tables, then select the desired service and click "OK".

  3. Rebuild the project, then invoke the Data Source Configuration Wizard again. You will now see your service in the "Data Sources" list. Select it and click "Next".

  4. On the next Wizard page, you can select exactly how your data should be connected.

    • Direct Binding to Data Source - the data-aware control will bind directly to the data source, without any go-between components involved.
    • Binding via the BindingSource Component - a new System.Windows.Forms.BindingSource component will be spawned to transfer data to your data-aware control.
    • Asynchronous Server-Side Data Processing - data will be transfered by the WcfInstantFeedbackSource component.
    • Server-Side Data Processing - data will be transfered by the WcfServerModeSource component.

    Select a required connection mode and click "Next".

  5. The final Wizard page requires you to enter the data service root URL and a table from which to display data. For server and instant feedback modes, you can also choose a data field that serves as a key expression, and sort all data by another data field.

    When you enter the URL, click the "Test Connection" button. If its initial red glow is gone and the button becomes disabled, the connection was established successfully.
  6. After you have filled all required fields, press "Finish". Your data-aware control is now bound to Open Data.

Expanded Binding To OData V4 Services In Code

The code below illustrates how to bind a Data Grid control to open data directly in code. The grid will bind to an existing "DemoService" service, generated by the OData v4 Client Code Generator. To learn how to bind to open data in Server or Instant Feedback modes, refer to the ODataInstantFeedbackSource and ODataServerModeSource component descriptions.

Expanded Binding To OData V2 Services In Code

The code below illustrates how to bind to an existing "ServiceReference3" reference directly. To learn about binding in Server or Instant Feedback modes, refer to the WcfInstantFeedbackSource and WcfServerModeSource component descriptions.

How would you rate this topic?​​​​​​​