XPO – 11.1 Sneak Peek - WCF services for IDataStore

19 April 2011

In XPO v2011.1 vol 1, we added support for WCF Services. These improvements provide the capability to create service and client for IDataStore as easy as it can only be.

In order to support this feature, the DevExpress.Xpo assembly will reference assemblies from .NET 3.0. Unfortunately, Visual Studio 2010 does not allow building projects whose Target Framework is set to 2.0, if they reference .NET 3.0 assemblies. To bypass this, it is necessary to set Target Framework to 3.0. Quite surprisingly, other Visual Studio versions do not demonstrate the above problem.
This does not mean that an application will not work on a machine that has only .NET 2.0 installed on it. If the project does not use the functionality of .NET 3.0, it will work just as before. Therefore, it should not affect your clients’ installations at all.

Let’s learn more about the implemented feature from a simple example.
For the beginning, we will create a new WCF Service Application project. Then, we will add references to the DevExpress.Data and DevExpress.Xpo assemblies and remove files with auto-generated interfaces for the service.

The next step is modifying the service class as follows: 

using DevExpress.Xpo;

using DevExpress.Xpo.DB;

namespace WcfService1 {

    public class Service1 : DataStoreService {

        public static IDataStore DataStore;

        static Service1() {

            string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "ServiceDB");

            DataStore = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);


        public Service1()

            : base(DataStore) {




To finish with the service, we will need to change some binding properties in its web.config file:



        <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">

            <!-- Service Endpoints -->

            <endpoint address="" binding="basicHttpBinding" contract="DevExpress.Xpo.DB.IDataStoreService">


                    <dns value="localhost"/>







            <behavior name="WcfService1.Service1Behavior">

                <serviceMetadata httpGetEnabled="true"/>

                <serviceDebug includeExceptionDetailInFaults="false"/>





Now our service is ready, and it is time to implement the client part.
For the client, we will add a Console Application into our existing solution. Then, we will use the Persistent Object item template for a  Customer class:

using DevExpress.Xpo;

namespace ConsoleApplication1 {

    public class Customer : XPObject {

        public Customer(Session session) : base(session) { }

        string _CompanyName;

        public string CompanyName {

            get { return _CompanyName; }

            set { SetPropertyValue("CompanyName", ref _CompanyName, value); }


        string _CompanyAddress;

        public string CompanyAddress {

            get { return _CompanyAddress; }

            set { SetPropertyValue("CompanyAddress", ref _CompanyAddress, value); }


        string _ContactName;

        public string ContactName {

            get { return _ContactName; }

            set { SetPropertyValue("ContactName", ref _ContactName, value); }


        string _Country;

        public string Country {

            get { return _Country; }

            set { SetPropertyValue("Country", ref _Country, value); }


        string _Phone;

        public string Phone {

            get { return _Phone; }

            set { SetPropertyValue("Phone", ref _Phone, value); }




The final step is to modify the Main() of our console application as shown in the code below:

using System;

using DevExpress.Xpo;

using DevExpress.Xpo.DB;

namespace ConsoleApplication1 {

    class Program {

        static void Main(string[] args) {

            XpoDefault.DataLayer = XpoDefault.GetDataLayer("http://localhost:64466/Service1.svc",


            XpoDefault.Session = null;

            using (UnitOfWork uow = new UnitOfWork()) {

                using (XPCollection<Customer> customers = new XPCollection<Customer>(uow)) {

                    foreach (Customer customer in customers) {

                        Console.WriteLine("Company Name = {0}; ContactName = {1}", customer.CompanyName, customer.ContactName);




            Console.WriteLine("Press any key...");





As you can see, we pass the address of our service into the GetDataLayer method of the XpoDefault class. It is very similar to what was already supported for Web Services.

Now if we run the service and client parts, we will see the following output:
Take special note that the port number in the connection string may be different. You can check it in the properties of the service project in the Solution Explorer:

Happy XPOing!

27 comment(s)

This is great !

But query on slow wan can be expensive ... Can you expand the example to add caching (with DataCacheRoot on the server and DataCacheNode on the client) ?

19 April, 2011
Bjoern Isemann_1

can't wait to see that functionality in XAF in the future. Would be great if you can use a wcf service to build server-client apps with XAF. Thats something i'm missing (or maybe haven't found yet).

19 April, 2011
Slava D (DevExpress)

@Luca Poretti:

A blog post about data caching is being prepared and will be ready soon.

19 April, 2011
Dennis (DevExpress Support)


XAF is still a regular XPO application by its domain, and so it was always possible to build client-server applications, communicating via WCF and other communication channels.

There are some examples in the Support Center and blogs: 1) search.devexpress.com

2) community.devexpress.com/.../xaf-10-advanced-data-layer-features.aspx

If you need any further assistance on this, please feel free to contact our Support Team.

What we did as part of the feature described in this blog is that we just made it much easier for our customers to build service and client applications communicating via WCF. Now instead of implementing your own IDataStore and other implementations, you can use the out-of-the-box solution with ease - just create a service derived from the standard XPO service class and specify the service's address on the client. That's it.

19 April, 2011
Paul Cunningham

Hello Dennis,

What's the difference between DataStoreService and XPODataService (already defined in DevExpress.Xpo.Services) ?



19 April, 2011
Nate Laff

Are there speed advantages to this method vs. direct sql queries over the wire in an internet app scenario?

19 April, 2011
Dennis (DevExpress Support)

@Paul: The latter class is a part of the OData Provider for XPO. I suggest you check out the tv.devexpress.com webinar video, for basic information on it.

It is also mentioned at the end of this awesome video: tv.devexpress.com (stop at ~1.05). I hope you find this information helpful.

19 April, 2011
Dennis (DevExpress Support)

@Nate: I doubt whether anything can be faster than a direct call to the database. In any case, the difference in speed between these two methods will not be enough to worry about...

I suggest you review a similar ticket in the Support Center, for more information: www.devexpress.com/issue=Q309614

The main point of using WCF for IDataStore is to build distributed client-server applications. For instance, a client can be connected to a middle-tier service and in general you may not know anything about what stays behind this service (database or other services). I hope this makes more sense.

19 April, 2011
Nate Laff

Dennis, thanks. Yeah, I get the idea of distrubuted services. Was hoping for an additional "Server Mode" effect, where the call is made to the service, and all processing happened on the server end rather than client creating increased performance in scenarios like my own :)

19 April, 2011
Glen Harvy

At last there's something in 2011 that I am really looking forward to.

Can you please zip up the VS Project for this simple example and make it available for download. I can then use that as a training aid as well as a base to build on.

Thanks ...

19 April, 2011

Great to see that. I'm really looking forward to get my hands on this!

20 April, 2011
Dennis (DevExpress Support)

@Glen: Thank you for your input. As always, any published feature in the product should have a demo + docs. This particular one is not an exception. There will be several demos, showing new XPO features.

@Sascha: We are glad to hear that you liked this feature! Thank you for your feedback!

20 April, 2011
Dennis (DevExpress Support)

@Nate: Again about speed, we would bring more impression of what happens behind the scenes and how it may affect the performance.

When using WCF,  queries and results are packed in single batches (the SelectData and ModifyData methods of IDataStore). When using direct queries, the select statements are transported one by one, the update statements may be packed in batches for certain connection providers only.

So, if you have a fast channel with a large ping, WCF may be faster in certain cases, especially if you enable compression for it (there should be an SDK sample, showing how to do this. However, there is no definite answer on what is faster - everything depends on certain situations.

Hope you find this information helpful.

20 April, 2011
Theodore p

It’s always great to see new features in XPO! I attempted to create a publisher using WCF almost three years ago. It turned out to be a nightmare that cost me many days of hard work and ended up in the trash bin. This one looks ridiculously easy! Well done!

20 April, 2011
Dennis (DevExpress Support)

@Theodore: Thank you for your feedback! I hope you will really enjoy this new approach once you get your hands on 11.1. Please share with us your feeling after that. Thank you in advance!

21 April, 2011
Dennis (DevExpress Support)

Will this play nicely with authentication? Something like BASIC auth or some based on membership providers? That would be really nice!

29 April, 2011
Vassilios Pallis

Is that means that we can at last use WCF with XPO in Silverlight 4 Applications ?

4 May, 2011

Dennis, is there better XPO support for RIA Services coming? I tried it, and there is a SC article about it, but it's very hard to do.

4 May, 2011

In this blog post we will talk about peculiarities of using IDataStore WCF services in Silverlight projects

16 May, 2011

In the two previous blog posts, we already described how to provide the IDataStore and ICachedDataStore

17 May, 2011
Vassilios Pallis

I followed exactly the example but i cannot get it to work. The connection is always empty. You don't mention anything about connection string and how to build it.

23 May, 2011
Dennis (DevExpress Support)


Please check out the following line in the service code:

string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "ServiceDB");

Then we connect to our service from the client:

XpoDefault.DataLayer = XpoDefault.GetDataLayer("localhost/Service1.svc", AutoCreateOption.DatabaseAndSchema);

Please feel free to contact our Support Team in case of any further difficulties.

10 June, 2011
Ivan Rodriguez_1

Is not possible to use the Target Framework 4.0 ? It's a must in my project. I tried to use Framework 4.0 but did't work, only worked wtih 3.0

11 November, 2011
stefano del furia

Hi, what about authentication? Something like BASIC auth or some based on membership providers?

I have created an HttpModule but i don't know how to pass the credential !!!

18 December, 2011
Dennis (DevExpress Support)

@Ivan: Yes, it is possible to use it with .NET 4+

You can check a working example at www.devexpress.com/.../Q532928

We are also planning to make these sample downloable from www.devexpress.com/.../List

23 October, 2013
qd kent

Hi, Dennis,

We have built our application using XPO that consuming the DataStore WCF service。But I found that ,  connectionString in method  <string connectionString, AutoCreateOption defaultAutoCreateOption) (version 18.2)> does not support WCF svc URI any more in .net core。So we can not extend  our application using the current DAL infrustructure for .net core apps.

Do you have the plan to support WCF datastore in .netcore that shall make users extend app in .net core  easily, or  they must rewrite the whole DAL code for .net core apps?  

I do think it is a big problem if XPO do not support WCF Datastore client in .netcore.

29 April, 2019

Please login or register to post comments.