Using Entity Framework, call another WCF Data Service from a WCF RIA Service.

c# entity-framework silverlight wcf-data-services wcf-ria-services


I would like to use WCF RIA Services to access data from my Silverlight Application. However the data is not provided from a local data storage, but from another WCF Data Service (I'm accessing an external CRM system). I don't want to access the external service directly because I have to mash up data from several data sources within my RIA service.

Is this possible an what would be the easiest way to achieve this? Some source code in C# would be appreciated.

EDIT: The central problem is how to fill an entity from an external service in an easy way. There is a related question, but the answer does not solve my problem.

5/23/2017 10:34:32 AM

Accepted Answer

I think your confusion may be that the Visual Studio wizard for adding a RIA service assumes you will use the EntityFramework for your data. I don't think you want to create an EF model out of the data from a second WCF service. Instead, create your RIA service to derive directly from DomainService and override the methods that you need. In each query method, simply query the remote service and return the result to the Silverlight client. In order for the RIA services magic code generation to work you will need to define a set of DTO objects in your app that wrap the results from the remote WCF service.

Here is a quick sample. Note - I just made this up to illustrate what I mean. You will need to put in calls to the actual service you are using and build error handling, input checking, etc.

namespace YourApp.Web 
    public class WcfRelayDomainService : DomainService 
        public IQueryable<Restaurant> GetRestaurants() 
            // You should create a method that wraps your WCF call
            // and returns the result as IQueryable;
            IQueryable<MyDto> mydtos = RemoteWCF.QueryMethod().ToQueryable();
            return mydtos; 
        public void UpdateDTO(MyDto dto) 
            // For update or delete, wrap the calls to the remote
            // service in your RIA services like this.

Hope that helps you out! See How to set up RIA services with Silverlight 4.0 and without EF for some more tips.

5/23/2017 12:10:52 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow