In this example we will create a WCF IDataStore service that will be used by our client (SilverLight Application) as a data layer. Instead of 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. Also all inquiries will be performed asynchronously to not block the UI thread.
Steps to implement:
1. Implement the WCF service as shown in the How to connect to a remote data service instead of using a direct database connection example.
2. Add a new Silverlight Application project.
3. Reference DevExpress.Data and DevExpress.Xpo assemblies.
4. Implement a Customer class as shown in the example's Customer.xx file.
5. Drop GridConrtol to MainPage.
6. Modify the MainPage.xx file as shown in the example's MainPage.cs file.
The MainPage uses Dispatcher to call the BeginInitializeDataSource method asynchronously, which creates a query and uses the EnumerateAsync method to set the GridControl data source.
As a result, you will see the following page:
At the development stage you can face the CommunicationException. This could be due to the attempt to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You will need to publish a cross-domain policy file and ensure that it allows SOAP-related HTTP headers to be sent. Also you can simply add your Silverlight application via the "Silverlight Application" window in the WCFService property window as shown in the following screenshot:
Troubleshooting1. If WCF throws the "Entity is 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:
Files to look at:• Customer.cs (VB: Customer.vb)
• MainPage.xaml.cs (VB: MainPage.xaml.vb)
• Service1.svc.cs (VB: Service1.svc.vb)
• Web.config (VB: Web.config)