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:
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.
Troubleshooting1. If WCF throws the "Request Entity Too Large" error, you can apply a standard solution from StackOverFlow: http://stackoverflow.com/questions/10122957/
2. If WCF throws the "The maximum string content length quota (8192) has been exceeded while reading XML data. " error, you can extend bindings in the following manner as per http://stackoverflow.com/questions/6600057/the-maximum-string-content-length-quota-8192-has-been-exceeded-while-reading-x:
<bindings> <basicHttpBinding> <binding name="ServicesBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" > <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647"/> </binding> </basicHttpBinding> </bindings>
Files to look at:• Program.cs (VB: Program.vb)
• Service1.svc.cs (VB: Service1.svc.vb)
• Web.config (VB: Web.config)