I have some Entity Framework entity classes in their own assembly and they are shared amongst WCF and clients like asp.net and WPF. It works as it should :-)
Problem is now I need to share this assembly with Silverlight - please note I am not using RIA services and I am unable to use ria services as I am locked into wcf services. I know with RIA services it's transparent but I don't have this option.
Considering that it's not possible to share (as far as I know) assemblies created in .net with Silverlight - how do I get the Entity classes into Silverlight (client) .. actually I am using POCO (Entity Framework 4).
I have an article that talks about the solutions. Sharing code between Silverlight and .NET
Related
Having a difficult time trying to setup a WPF application that takes advantage of RIA Services and Entity Framework 5.0.
What makes this even more confusing, is how do I set all of this up asynchronously?
There is hardly any information out there. :(
That's because there is no RIA Services implementation for WPF (ie. the proper .NET framework).
In the context of WPF, WCF Data Services is nearest of kin in terms of what it is used for, but it's not compatible.
Furthermore, RIA Services is async-only (but doesn't support the async/await paradigm natively), whereas Entity Framework is sync-only (async support comes in EF6 I believe).
I have created
a) a basic application MVVMLight framework.
b) another project in the same solution having an Entity Model (NorthwindModel.edmx).
c) a WCF service to retrieve data through the entity model.
Now I want to link a, b, and c together. How do the project mentioned in a) above interact with the other two? How can I display/bind the data using the edmx in the View of the MVVM?
Do I have to write code in the ViewModel class/classes to achieve this?
I browsed through many websites, checked many questions here on SO, but none seems to throw any light for me in this regard. The examples that I saw involved a lot of coding in the ViewModel class. If that's the only way to go about it, then why do people say MVVM with Silverlight requires very little coding?
You can use WCF RIA Services to bridge the gap between ASP.NET and Silverlight.
Get Started - WCF RIA Services
You will need to create a Silverlight library project, add entity files as link to the project.
This will enable you to use the Entities in your Silverlight application.
how to add files as link
Actually you need a Web project where you host your webservices, then you need your business logic layer and data access layer where you retrieve data, then you need the entities and a silverlight entities project. After this you create your Silverlight project and add web service reference to it and thats it, now you are ready to use MVVM.
I think you could use this to refer how to build a solution with multiple projects and also have entity framework with WCF RIA services.
To ensure you project is running MVVM light you could use Nuget to inject the necessary files into your client project. Information on this is available here
What VS project type should I choose so that the data-transfer-objects that I create in it can be accessible in both in my Silverlight project as well as my WCF service project.
(I want to be able to reuse the DTOs that I define in both projects instead of having VS generate a new set in my Silverlight project when I create a web-service reference to the WCF service).
IE, my question is can the project be a Windows class library, or should it be a Silverlight class library (so as to reference it in both my Silverlight project as well as the WCF project).
You've got three main options:
Create two class library projects (one targeting Silverlight, the other the .NET Framework), and share the files between them, as I discuss in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-3.aspx
Create your class library as a Silverlight class library. Silverlight applications can't reference class libraries that target the full .NET Framework, but applications targeting the full .NET Framework (such as you WCF Service) can (generally) reference class libraries that target the Silverlight runtime.
Try out the Portable Library Tools (currently in beta): http://blogs.msdn.com/b/sburke/archive/2011/01/23/3-screen-coding-is-here-portable-library-tools-allow-you-to-target-multiple-net-platforms-with-one-binary.aspx
Have you thought of using RIA Services (or WCF Data Services) instead of a plain WCF service? RIA Services / WCF Data Services handles this problem for you, and adds other great functionality into the mix.
Hope this helps...
Chris Anderson
Since days I am reading and researching and still struggling how to create the perfect infrastructure. Since there are no Prism 4.0 templates as such, I came up with a strategy, but I need to be sure this is the right strategy and I would appreciate an advice from experienced PRISM/RIA developers.
I use PRISM 4.0, RIA Services 1.0 Sp1 Beta, Silverlight 4.0, Entity Framework 4.0
1) Client side
I created first a "Silverlight Business Application", which creates a Web.host and a Silverlight client application with implemented RIA authorization. The initially created Silverlight client application shall be used as the Shell project.
2) Infrastructure project (Common)
This project would contain some common Prism MEF attributes and perhaps the entity models that are auto generated by RIA as well as the Service Interface. The idea is to create a simple Silverlight Class Library, and under Properties of the project, I would select for the dropdown ‘WCF Ria Services Link ’ to point to the host.Web project that contains the Ria Services. Then after the rebuilding, I am able to see the entity models within the Class Library and these could then be shared between the prism modules to feed their ViewModels etc.
3) Service layer
Should I create the EF4 Model on the Web.host project and add the Domain Service in there? Then I would extract an interface from the Domain Service and put the interface into the Infrastructure (Common) project. The Web.Host therefore needs to reference the Infrastructure (common) project to get access to the interface. On the client side the interface may be used by MEF to retrieve or mock the service . However I am concerned about the service referencing a common project that contains also the client-side generated entities.
4) Authorization
Also a bit concerned about the authorization, shall I leave everything on the Shell project? Or do I have to move anything to the Infrastructure (common) project to share it?
Since this is my first time designing with PRISM, I might have misunderstood or forgotten some aspects. Please feel free to improve my suggestions.
Your help is highly appreciated
Kave
After two weeks of intense research, this blog couldn't put it better together:
http://blogs.msdn.com/b/dphill/archive/2009/08/17/prism-and-net-ria-services.aspx
There're nice Quick Start templates for Prism, I found it at blog http://blogs.msdn.com/b/dphill so it looks quite nice, I used it also created RIA Service library so everything now is separated:
1) WEb project
2) Ria Service on web
3) generated RiaService client code as separate and shared assembly and it is used by modules. that's it.
I'm rewriting an LOB application whose architecture is like this:
Silverlight && Windows Mobile -> WCF
-> Entity Framework -> Database.
The mobile app was supposed to be able to do certain things as the silverlight app. What benefits would I get from using RIA Services here? Whats the advantage and disadvantage of RIA Services over WCF?
.NET RIA Services was created for Silverlight that runs in the browser. Silverlight is running a special version of the the .NET framework and in an N-tier application Silverlight is unable to share assemblies with the server side. By employing some clever code generation .NET RIA Services makes this gap almost invisible to the developer. Classes similar to the domain classes are code generated on the client side, and ways to move objects back and forth between client and server are also made available.
You will probably be able to call into a .NET RIA Service from Windows Mobile, but I don't think it will particular easy and currently you may in fact have to reverse engineer what's sent on the wire (JSON is used). WCF on the other has a much more broad scope, but doesn't support Silverlight development in the same way that .NET RIA Services does.
If you are writing a Silverlight only N-tier application .NET RIA Services are very powerful. If however Silverlight is only one of several clients WCF is probably a better choice.
Please note the .NET RIA Services hasn't been released yet, but a preview is available for download.
WCF RIA Services introduces several solutions for challenges you run into when using WCF from Silverlight. For instance, asynchronous loading of queries using the EntityQuery<T> is much easier than the Begin..End solution offered by WCF. Also, RIA provides integrated change tracking from your client that allow to submit or reject multiple changes as one change set. RIA will bundle all these changes into one request, but from your Domain Service it behaves as it were individual calls. As a long time WCF developer I can tell you that that is a breeze.
Ria services are created just to be used with Silverlight. They are substantially a standard "package" ready to be used by Silverlight. The advantage is that you have a lot of services without need to write code i.e.:
Support for data annotations
Support for membership provider and login
Support for transferring to silverlight server side generated exceptions. There is a difficulty in silverlight that make difficultthe normal error transfer of exception through FaultContract. The point is that the browser is not able to handle all error codes. Ria services solve this with a trick
All things done by Ria can be done with WCF and with other available software and in particular with Wcf data services. For instance for data annotations I found this library that do a better job than Ria services, support for membership just require activating the already existing membership endpoint of a WCF service, and finally the exception problem is easily resolved by writing a WCF behaviour. Code is available here:http://www.silverlightshow.net/Storage/10Tips.zip
The point is that with Ria Service you have all this in a mouse click!. On the other side Ria Services are really difficult to customize...so if you don't like the standard solution they offer you simply can't use them
RIA Services is built on top of WCF. With the PDC release, this will be much more evident. RIA Services simplifies the client-side programming model so that it matches very closely with your server-side DomainService and entities.
Regardless to the answer:
RIA Services is built on top of WCF.
With the PDC release, this will be
much more evident. RIA Services
simplifies the client-side programming
model so that it matches very closely
with your server-side DomainService
and entities.
For me (and I guess that for the topic author) it is not clear what RIA services provide also besides access to the DomainService (which is same thing provided by WCF)?
Thanks.
Until there is a formal release of WCF RIA Services, I don't think there is a definitive answer to this question. As of the current Beta (for VS 2008, SL 3), RIA Services does not hide the asynchronous nature of service calls; you still need to provide a callback method. Also, RIA Services does not currently support user-defined classes (or collections of user-defined classes) as either parameters or return values on RIA service calls. I'm also running into trouble providing non-editable entity classes through RIA Services. (The error says the entity collection isn't editable. Yeah, that is actually what I want....)
At this point, I need to fall back and take another look at making plain old WCF work. That's not so simple, given the size of the application we're developing, but it seems to be the workable solution until MS fixes some of the current problems with RIA Services.
.NET RIA Services had been named as WCF RIA Services in PDC which was held in November 2009. Since it is built on top of WCF, hence the name WCF RIA Services.
You'll need to use WCF RIA Services for building N tier application involving database(or any information that needs to be carried along the tiers).