I have started using asp.net MVC and as traditional way I want to keep my data access layer in WCF service. How can I achieve that using asp.net MVC ?
Scenario
I started a test application in asp.net MVC which Displays, Inserts and Edit data.
I successfully created that by adding 'ADO.Net Entity Data Model'.
So now if I wanted to move this dataaccess layer in WCF service, i.e. a WCF service with methods like GetData(), UpdateData(), CreateNewData(), how can i achieve that?
Short Answer:
You just need to move your dataaccess layer into a WCF service, expose it and then call it from your MVC application.
Long Answer:
1) I recommend going through Scott Guthrie's Nerd Dinner walkthrough to get a really good understanding of MVC basics.
2) The following blog goes through the process of writing a Layered ASP.NET MVC Applicaiton with a WCF Service (Parts III & IV specifically concentrate on WCF & MVC interaction):
Part I (General Concepts)
Part II (Building a Repository)
Part III (Building The Service)
Part IV (Using The Service)
I haven't read the linked arrticles in detail (just skimmed them) but they seem to give a decent overview of the process.
Asp.net MVC Application With Wcf Service
http://patilranjeet.blogspot.in/2014/11/aspnet-mvc-with-wcf-sample.html
Related
I need a suggestion: I currently have an ASP.NET web forms application (pretty large scale) with three tier architecture and ado.net for database communication.
Application structure is
Web > BLL > DAL > BO,
BLL for business logic and DAL for database interaction using ado.net (stored procedures).
There are other 4 apps connecting with BLL that make applications tightly coupled. Now I have to redesign one application so we decided to change underlying technology.
And I currently have few options:
Change front end layer and rewrite complete app to Angular and have API layer on BLL (most time consuming and complex solution I guess)
Change font end to ASP.NET MVC and directly call BLL from controller (we can reuse existing html mostly, but app will remain tightly couple and still monolithic)
Change front end to ASP.NET MVC and write API layer on BLL and connect controller to BLL via API (not a good idea to add an extra http request for every sever call client > controller (server) > API ( server).
Please suggest any alternative approach. Is this good option to rewrite complete complex application from ASP.NET MVC to Angular?
I would suggest using ASPT.NET CORE WebAPP and one or more ASP.NET CORE Web API, REST, microservices, so you don´t need to expose your services on the web and would be better to maintain it and for huge systems. Used of EF core, with CQRS pattern, is a very good choice within your WEB API so you can implement your BLL on it. Try to use to SOLID principles, mostly the D, dependency of inversion, that has already a built in IOC container so you apply the dependency of injection on it. Don´t forget to secure the system with authorization and authentication. OAuth 2 is a good way to go!
I have a ASP .NET MVC4 application using Entity framework CodeFirst and I want to expose its data with WCF data services. I don't know where and how to begin.
Could you give me ways to follow ?
My final goal is to deploy this service on Windows Azure PaaS.
Create a new Web Application project within your solution and add a new WCF DataServices item.
This WCF DataSercices should reference the same business layer as the one you might use within your controllers/model builders in your ASP .Net MVC4 application.
Then have a look here to learn about how to deploy on Azure.
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
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.
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.