KB Article K18557
Visible to All Users

GridControl - How to use the WcfServerModeSource component as a data source

Description:
This article provides a step-by-step instruction on how to create a WCF Data Service, associate the WcfServerModeSource component with it and use it as a GridControl datasource

Answer:

  1. Create a new Windows Forms application.
  2. Add new WCF Service Application project to a solution:
  3. Add an Entity Data Model to the WCF Service Application project:
  4. Generate Entity Data Model from a database (in current tutorial we will use the AdventureWorks database):
  5. Add a Wcf Data Service to the WCF Service Application project and configure it as follows (note that the WCF Data Service template is available in Visual Studio 2015, but not in Visual Studio 2017):
C#
public class WcfDataService1 : DataService<AdventureWorksEntities>{ // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } }
Visual Basic
Public Class WcfDataService1 Inherits DataService(Of AdventureWorksEntities) ' This method is called only once to initialize service-wide policies. Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration) ' TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. ' Examples: config.SetEntitySetAccessRule("*", EntitySetRights.AllRead) config.SetServiceOperationAccessRule("*", ServiceOperationRights.All) config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2 End Sub End Class
  1. Build the solution and then add a Service Reference to the Wcf Data Service:
  2. Place the GridControl on a form. Make sure that the DevExpress.Data.vXX.Y assembly is added to the project references.
  3. Import a WcfServerModeSource.ServiceReference1 namespace to a Form1 code and create an instance of the AdventureWorksEntities type:
C#
AdventureWorksEntities db; public Form1(){ InitializeComponent(); db = new AdventureWorksEntities(new Uri("http://localhost:61617/WcfDataService1.svc")); }
Visual Basic
Private db As AdventureWorksEntities Public Sub New() InitializeComponent() db = New AdventureWorksEntities(New Uri("http://localhost:61617/WcfDataService1.svc")) End Sub
  1. Create an instance of the WcfServerModeSource type and assign it to the GridControl.DataSource property:
C#
private void Form1_Load(object sender, EventArgs e){ gridControl1.DataSource = new WcfServerModeSource() { KeyExpression = "EmployeeID", Query = db.Employee }; }
Visual Basic
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) gridControl1.DataSource = New WcfServerModeSource() With {.KeyExpression = "EmployeeID", .Query = db.Employee} End Sub
Show previous comments (5)
DevExpress Support Team 10 years ago

    Hi Nigel,

    To add a fixed filter condition, use the WcfServerModeSource.FixedFilterCriteria property. Refer to the Criteria Language Syntax document that describes how to build a filter string.

      How to use pagination on a winforms project without creating an wcf service project ?
      Can I just put wcfServerModeSources on the winforms project itself ?
      Or some other way ?
      Also I am not using entity framework, but DataTables build and filled in code

      DevExpress Support Team 6 years ago

        Hello,
        To avoid any misunderstanding, I've created a separate How to use pagination on a winforms project without creating an wcf service project ? ticket on your behalf. Please refer to it for further discussion.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.