Call another WCF Data Service from WCF RIA Service using Entity Framework

10,070

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 
{ 
    [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 that helps you out! See How to set up RIA services with Silverlight 4.0 and without EF for some more tips.

Share:
10,070
slfan
Author by

slfan

Dipl. Ing. ETH Zürich (Switzerland) / dipl. Wirtschaftsing. STV MCPD Web / Windows .NET 4.0 / Silverlight + Azure / MCSD Web .NET 4.5 / Xamarin Mobile Developer Microsoft Certified Trainer since 2005 Software Developer and Architect C#, ASP.NET/MVC, .NET Core, WPF, Services, WCF, Entity Framework, Azure, Xamarin

Updated on June 04, 2022

Comments

  • slfan
    slfan almost 2 years

    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.