Call another WCF data service from RIA WCF service using Entity Framework

I would like to use WCF RIA services to access data from my Silverlight application. However, the data is not provided from the local data store, but from another WCF data service (I refer to an external CRM system). I don’t want to directly access an external service because I have to flush data from multiple data sources in my RIA service.

Is it possible that it would be the easiest way to achieve this? Some C # source code would be appreciated.

EDIT: The main problem is how easy it is to populate an object from an external service. There is a related question , but the answer does not solve my problem.

+4
source share
1 answer

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

Here is a small example. Note. I just did it to illustrate what I mean. You will need to put the calls in the actual service you are using and build error handling, input validation, etc.

namespace YourApp.Web { [EnableClientAccess] 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. RemoteWCF.UpdateMethod(dto); } } } 

Hope this helps! See How to Configure RIA Services with Silverlight 4.0 and Without EF for more tips.

+2
source

All Articles