Silverlight and n-Tier Development - -How is it done? - silverlight

I've asked several questions on Silverlight the last day or two (I have no experience with it), and I've had some high-level questions answered. I have another high-level question. How is N-Tier development done with Silverlight? What I am considering is a browser based UI and then a c# back-end containing all the business logic and database code. How would a Silverlight client application communicate with such a back-end sitting on another server? Would it be done via Web service calls, WCF or something else? What is standard practice?
Thanks!

For the projects I've worked on. Typical practice is Silverlight providing a client and then communicating back to the back-end via WCF services.
The business logic is then spread/duplicated across the client and the backend.

You'll want to be looking at the WCF RIA Services for this. In combination with Entity Framework this will approach the sort of thing you need.
The Entity Framework creates model that you can extend and include some business logic.
The Domain Services then allow you to expose access to the model and any other range of operations you need via WCF.
The tooling that RIA Services adds to the Visual Studio will dynamically create in the Silverlight application the client side of this Domain service. There is even a provision for you create C# source that is shared by both by both Silverlight and the server code.

If its Silverlight 3 RIA is a better choice to work with. AnthonyWJones has pointed it right, There is a provision to have a shared Source between Client and Server usually Entities code should be shared in both Client and Server to get full advantage of RIA validation and other stuff.

Related

Why would anyone use WCF basicHttp webservice over WCF RIA Services in Silverlight?

So, I've been using WCF Ria services for a few months now and I am wondering why would anyone use WCF basicHttp webservice over using WCF RIA Services?
Someone told me that RIA Services is not good for Enterprise Level Applications and I am wondering why?
W/out RIA it seems you have to write validation logic in 2 areas, client and server. Also, RIA handles roles and membership fairly easily.
How much extra work is involved if you want to use WCF basicHttp webservice? What is the benifit over using RIA? and.. Does anyone have any good examples of an enterprise level silverlight application using wcf basicHttp webservice?
Thanks!
The issues with WCF support in Silverlight relates to the limited subset of the .NET Framework embedded in the Silverlight plug-in as it's essentially a scaled down version of the .NET Framework. As a result of the scaled down .NET runtime in the Silverlight plug-in, it does not have the same full support for WCF that you get from standard .NET projects. This was done to make the initial download of SL quick from a client perspective and increase time-to-market of SL as a product. Keep in mind that the SL plug-in has no dependency on an existing .NET framework being installed which is why Linux, Windows Phone 7, and OS X versions are on the market.
As time has progressed they continue to add in-demand features in. For example, Silverlight 5 will support WS-Trust (see here for a complete list of new features in 5).
I recommend you read this resource to see what you may miss out on by trying to call WCF Services from the client:
http://msdn.microsoft.com/en-us/library/cc896571(v=vs.95).aspx
Keep in mind you could very easily proxy out calls to more complex WCF services through RIA Services endpoints which are in effect calling the service directly from server-side.
As for using standard WCF instead of RIA ... there are advantages when your middle tier has multiple client types, though with RIA you could simply expose your endpoints out as SOAP 1.1 endpoints and require people to connect using that paradigm instead of WCF. You do not have to use RIA or nothing; you could mix and match to meet your requirements as you see fit. Personally I am big on just using RIA if at all possible.
It's fair to say RIA Services has had its growing pains. Some of my biggest bugbears with it (such as not having the ability to return complex objects that aren't entities from Invoke methods, and the lack of decent support for being used in an MVVM way) have mostly been fixed in RIA Services SP1. Some people I know using it in huge enterprise applications have had major headaches with it (at least in the early days). I'm not quite sure where things stand now in that respect, as to whether their particular problems have been resolved yet.
That said, I personally think it's a fantastic technology. It makes tasks that are painful with standard WCF services easy (my favourite is being able to specify queries on the client on methods in your domain service that return IQueryable, that execute on the server - making sorting/filtering/grouping/paging a breeze). Whether it's right for you depends on your scenario. It's designed primarily to make performing CRUD operations on entities easy, so if that's primarily what you need then its perfect. RIA Services is designed to be consumed by Silverlight application only however (at least for the moment). You can access them from other clients, but you don't get all the features that makes them so good. So if you need to support other client platforms, it may not be the right fit.
I think RIA Services is awesome, but ultimately it depends on your scenario as to whether they are right for your project. As a technology, it's geared towards particular scenarios, and isn't intended to solve all the world's software development problems. Some people who might complain about it possibly aren't using it in the way it was intended, and pushing its limits (that said, it isn't perfect either, and has had its issues). If you can possibly provide some more details (such as the scale of the application, the client platforms it needs to support, and the number of developers on the project), I'd probably be able to give you some more helpful advice.
Hope this helps...
Chris

How to architecture business layer or wcf ria services

We are building a new system from scratch and have decided on SL4, WCF RIA Services and EF4.
So I see the WCF RIA services as the business logic of the SL client, but can it be used as a general business logic layer, that can be used by other parts of the application. As an example the WCF RIA service will have security implemented (such as who is allowed to do what with which objects). But this security implementation should also be by other parts of the system and not only by the SL client.
To avoid having this logic duplicated my idea is to use the WCF RIA service as a general business layer meaning that if other parts of the system needs access to the datalayer they would need to go through this layer.
But is this an ok usage of WCF RIA?
Thanks
What you're describing is the standard WCF RIA pattern and is how the WCF RIA team designed the system to work.
WCF RIA will allow you to get end-to-end access to your EF4 entities and hide your business logic behind the RIA service interface. You can apply authentication and authorization attributes to your entities in the service definition (domain service class) at either the class level (all methods in the service contract) or the method level for more granular control.
The only major flaw I see in your plan is "other parts of the system needs access to the datalayer they would need to go through this layer". WCF RIA at this stage only plays well with Silverlight (and maybe ASP.NET MVC? I am not sure). Microsoft eventually intends to extend RIA Services to be consumed by any kind of .NET application but at this stage it's really a Silverlight-only thing. This means that you'll miss out on a lot of the WCF RIA goodies with your other non-Silverlight applications. However I believe you can still expose the WCF RIA service as an ordinary WCF service, including the authentication/authorization layer. You'll just miss out on the automatic proxies, code generation, etc.
There are still several ways of using this service layer from outside of Silverlight however. You can expose your EF4 entities with an OData endpoint or SOAP/REST service. For more details on this, check out this article.
In the big RIA project we usually have so many modules ( Business modules, licensing, authorization, Audit modules etc.) and obviously there are some modules that need to be accessed across other modules and also some across the SL client. So I believe your concern is a typical architecture side on how you make this properly distribute in a big application. As in any .NET project, you can modularize it in to different library projects. That means you can appropriately make some as RIA Service Class Library project or else typical reusable .net libraries ( for example, Logging library)

Silverlight / Prism / RIA : How to create the optimal infrastructure?

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.

How to rearchitect Hibernate DAO layer of ASP.NET app to move it to Silverlight?

Last try to get an answer on this.
I have a simple ASP.NET app which uses Hibernate for data access.
GUI can call methods on Customer object like "CalculateTotalSumOfOrders()".
Lazy loading (even though it's not optimal) will work for me, and when Orders and OrderLines collections are referenced in the domain objects, they will get automatically fetched from the database.
Now let's assume I am rewriting the same very app to Silverlight because it looks better than ASP.NET.
I am NO longer able to do lazy loading or data access, because Silverlight client runs in the browser.
How can I solve this without thinking too much about what kind of service to use to get data into the Silverlight client?
Your best bet for supporting all of those platforms is to use a web service. There are many different flavors that you can choose from, .NET 2.0 Web Services (ASMX), WCF, REST, if you are using Silverlight, you may want to consider using WCF + LINQ to SQL which is demonstrated here. That combination can also be used in ASP.NET (if running on .NET 3.5) and Windows Desktop Apps (again .NET 3.5).
Also an open source project called InterLinq might be interesting to you, basically it allows you to build LINQ to SQL queries on the client side, and then transmit them through WCF to a server that executes the query and returns the result. That can be found here. I have experimented with it in the past and it works quite well.
One option that would support Silverlight and Windows clients would be the new ADO.NET Data Services in .NET 3.5 SP1. These are a set of services that expose your database schema through a WCF interface. You can then retrieve the data from Silverlight or a Windows Client using a WCF client.
As #McWafflestix has said, you won't be able to do lazy loading any more, but in my opinion that's a good thing because retrieving data is now a much more "expensive" operation.
You're trying to take a server-side app that interacts with your database and does lazy loading, and convert it into a client-side app without a lot of work? Sorry, it's just not going to work. What you need is a major rearchitecting of your application.
Sorry...
*
"That's okay because I'm quite early
there. How would you rearchitect it to
support both ASP.NET, silverlight and
windows clients with minimal
overhead?"
*
I know I am answering this question way past the expiry, anyhow here goes. I would suggest you use the MVP design pattern; this would help you build multiple "Views" to work with your Model. In order to ensure that you support Windows clients, you would have to expose your Business Layer using a services layer (read WCF).

RIA Services versus WCF Services

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).

Resources