WCF RIA And ASP.NET MVC 3 - asp.net-mvc

So I am looking into solutions for developing a Silverlight web app, and right now ASP.NET MVC and WCF RIA have caught my eye.
Should these two be used in conjunction with one another? Or does the 'MC' in MVC play the role of the RIA services?
Would it be redundant to use both in the same web application?
Thanks.

WCF RIA Services work great with Silverlight. So you just need to host your SL application somewhere, a static HTML page could work just great. You don't really need ASP.NET MVC.

Asp.net MVC is basically used for visualized applications. WCF RIA Services are API oriented and are supposed to be used with Silverlight. Or even preferred.
You could of course write an Asp.net MVC application that would return Json results for every request but what would be the point in doing that? In that case (if you would want to write all the code manually) you'd rather go with a standard WCF service instead.
WCF RIA Services are the fastest way to getting to your data in developer's perspective. Learn and use it. No better way basically.

Related

Silverlight/RIA Services and ASP .NET MVC/WebAPI

I did some research around but I have some doubts still about following topic...
I have Silverlight/RIA Services project that needs to have ASP.NET MVC look as well as WebAPI for some different clients.
So my question is following
Can we use somehow RIA Services with ASP.NET MVC 5?
And if not what is a painless way to represent all existing logic in ASP.NET MVC?
Thank you!
Ria services have nothing to do with look and feel.
A Silverlight app or a non plugin, which uses RIA services can be hosted in a web page created using ASP.Net.
Can we use somehow RIA Services with ASP.NET MVC 5?
Yes.
RIA services which could be used by an asp.net backend would not gain the benefit of RIA services because changes made in the backend end are not generated forward to an application such as a Silverlight plugin. It just becomes another way of accessing data.

RESTful services: WCF versus ASP.NET MVC

A very common approach to implementing RESTful services is by utilizing ASP.NET MVC to do so over WCF.
ASP.NET MVC has excellent RESTful support by via flexible URL routing and flexible HTTP Method mapping to controller actions.
WCF 4.0 now has excellent support for implementing RESTful service also using the same ASP.NET routing mechanism as ASP.NET MVC.
Question
What are your experiences working with either of the 2 approaches to create RESTful services and pros and cons encountered?
WCF services can be self-hosted. No IIS required. ASP.NET MVC is focused on delivering HTML, whereas the existing .net 4 WCF stack is focused more on XML and JSON.
The new http://wcf.codeplex.com is the next generation of REST on WCF and will be significantly more capable than the existing stack.
The new stack will be much better at supporting all different media types. It provides much better access to the underlying HTTP protocol. It will be much more testable and will make it easier to plug in reusable handlers to add standard behaviours.
Take a look at Podcast from Scott Hanselminutes with Glenn Block where they discuss same issue and compares MVC and new WCF Web API.
http://www.hanselminutes.com/default.aspx?showID=284
I'd say WCF is better suited to build services, you can do it with asp.net mvc but it requires more ceremony

Architectural pattern for ASP .NET and Silverlight UI

do you know of any available architectural pattern where the most of the code could be shared between Silverlight and ASP .NET UI? I understand that Silverlight won’t work very well with MVC (although people are blogging on how they achieved this in fact what they did wasn’t pure MVC) and same applies to ASP .NET MVVM.
However, I’m pretty sure there is a pattern where all of your business and data layers could be re-used by both Silverlight and ASP .NET app?
The example of when this would be needed is if we created a web application using Silverlight for desktops and asp .net for mobile devices and iPad, assuming that everything but UI would be the same.
You could simply creat a business logic layer assembly that would be used by both the Silverlight and ASP.NET versions of the application, the UI would be different but they'd both be using the same business logic or whatever you want to call it. The trick however is that Silverlight is a client technology so the server-side piece would house all that shared logic and you'd need to then interface that through a web-service your client could talk to, but that goes without saying when it comes to Silverlight/client-side technologies.
Contrary to what you've heard: Silverlight works great with MVC!
As far as sharing code the simplest answer is to have a single implementation of your data layer and business objects in the MVC application and then expose this to your Silverlight application via web services.
Ideally this means that the only code in your Silverlight application is UI specific...
RIA Services works with both Silverlight and ASP.Net and provides both client and server validation via member attributes. Code is shared auto-magically between sever and client apps.
You can use WCF and/or Ria services for data layers.

How does ASP.NET MVC relate to WCF?

A Guide to Designing and Building RESTful Web Services with WCF 3.5, this article explains the foundations of REST and how it relates to WCF. MVC uses REST as the architectural model. I am guessing one can use the .NET MVC to create web applications that have both a front end and an API point, but I am not sure if the safe way of building the API is to build it with WCF and then use it in the MVC as a controller.
Please comment if the question is not clear, I will add or modify the text.
Theres actually a third option, ADO.NET Data Servies. Anyway, here how I see them.
MVC REST: Gives you full control over how to expose your data, you have to write all the code to get it up an running tho, e.g. serialization, deserialization, all the CRUD methods etc etc. Worht metioning that this being an MVC site means you are limited to exposing your service via IIS over HTTP(S)
WCF REST: More automation than MVC, a much more solid frameowkr than MVC REST, i.e. caching, security, error handling etc (basically all the stff you'd have to write yourself using plain MVC). Being WCF, you can host this in a variety of ways (e.g WS-, TCP) etc.
ADO.NET DATA SERVICES: The quickest way to get up an running with everthing ready to use, all you need todo is configure the global.asax, however you have to use an Entity Data Model, which you many not want to.
Personally, I would use either ADO.NET DATA SERVICES or WCF REST to build an API, consue that API in MVC site and then expose that API either directly, or by passing it through another layer.
ASP.NET MVC can serve as a REST endpoint for light services work, so I guess the answer to your question depends on how you define "safe."
Clearly WCF is designed specifically for creating REST endpoints, with all of the security implications that are implied thereof, whereas ASP.NET MVC is designed to create REST endpoints which can be used by ASP.NET MVC itself.
The following article shows how to create a web service using an ASP.NET MVC controller:
Create REST API using ASP.NET MVC that speaks both Json and plain Xml
http://msmvps.com/blogs/omar/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx
See also the following article from Phil Haack, which discusses an SDK the WCF team put together for users of ASP.NET MVC:
Rest For ASP.NET MVC SDK and Sample
http://haacked.com/archive/2009/08/17/rest-for-mvc.aspx
They are two different sets of technologies, only related by being built on .net
MVC is used to create websites and provides a model where URLs are routed to controllers and controllers deliver views to the user as the user interface.
WCF is a set of libraries in .net that are used to abstract the type of service (is it hosted in a windows service, as a webservice in IIS etc.) as well as the protocol (HTTP, TCP, MSMQ etc.) from the client and server which are communicating.
An MVC website may use WCF to connect to a web service, but that is just one of many options.

Which's the best performance between Asp.net MVC controller VS. Wcf for Silverlight Application?

I found that Asp.net Mvc controller can serve both Asp.net Mvc View and Silverlight application via DynamicActionResult(It can be Simple Action Result or Json Action Result depend on request type). So, I have 3 options for creating middle-tier for Silverlight application.
Pure WCF Service Every request to WCF must be declare in interface. So, it's strongly-typed connection.
Asp.net MVC Controller It can serve both Asp.net MVC View and Silverlight application at the same time.
Using both of them I found that it's possible to doing this by using the answer in the following link. I think, It doesn't good idea for creating both of them.
WCF Service with Asp.net MVC application
Which's the best performance between WCF Service and Asp.net MVC Controller?
Thanks,
Do you have the kind of service that would benefit from caching? If so, my testing says that MVC with Output Caching turned on is very much faster than WCF.

Resources