简体   繁体   中英

Call another WCF Data Service from WCF RIA 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 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM