Scenario
In this example, we will create a WCF IDataStore service that will be used by our client (Console Application) as a data layer. Instead of the direct connection to the database, our client will connect to a remote service, which is way more secure and thus important in many enterprise scenarios as database connection settings are not exposed to the client.
Steps to implement
1. Create a new WCF Service Application project and add references to the DevExpress.Data and DevExpress.Xpo assemblies and remove files with auto-generated interfaces for the service.
2. Modify the service class as shown in the Service1 file. This service initializes a connection provider and stores it in the static DataStore property, which is then used by the base DataStoreService class.
3. Change some binding properties as shown in the example's web.config file. At this stage, the service part is ready to work and we need to implement a client to consume data from our data store service (for demonstration purposes, we will create a Console Application).
4. Add the Console Application into the existing solution.
5. Add a new code file for a Customer class using the DevExpress v1X.X ORM Persistent Object item template. See a code of Customer class in the ConsoleApplication\Customer code file.
6. Pass the address of our service into the GetDataLayer method of the XpoDefault class. For this, modify the Main method of the Console Application as shown in the ConsoleApplication\Program code file. Please 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:
As a result, we will see the following output:
Important notes
If you are using an XAF client, then in the simplest case, you can just set the XafApplication.ConnectionString to the address of your data store service (http://localhost:55777/Service1.svc). Refer to the Connect an XAF Application to a Database Provider help article for more details.
See Also:
How to use XPO with a Web Service
Transferring Data via WCF Services
How to connect to a remote data service from a Silverlight application
How to create a data caching service that helps improve performance in distributed applications
How to implement a distributed object layer service working via WCF
How to connect to remote data store and configure WCF end point programmatically
Question Comments
Added By:
NBT Developers at:
5/28/2014 10:39:32 AM FYI on this part "If you are using an XAF client, then in the simplest case, you can just set the XafApplication.ConnectionString to the address of your data store service (http://localhost:55777/Service1.svc). "
Literally do this:
WebApplication.Instance.ConnectionString = "http://localhost:55777/Service1.svc";
XpoDefault.DataLayer = XpoDefault.GetDataLayer("http://localhost:55777/Service1.svc",
AutoCreateOption.DatabaseAndSchema);
XpoDefault.Session = null;
using (UnitOfWork uow = new UnitOfWork())
{
}