ASP 5 MVC 6 - Pros and cons: multiple web api services - use one or more projects? - asp.net

I want to migrate my WCF services to Web API / MVC6.
Currently I have one application hosting multiple WCF web services (http://{ip}/{app}/Service{x}.svc/{vs_endpoint}). This model is pretty good, we can separate the public services from internal services and we have control over each service in particular, although they all are under one single application.
Would I be able to achieve similar thing in Web API / MVC6, having one project for multiple services? From my initial investigations I understood I would need to do something along these lines.
If yes, it would be nice to have some recommendations how to structure this project.
Also, can you share some pros and cons about one vs multiple projects to host these services?
Thank you in advance!

Yes you can achieve this by using either separate controllers or logically grouping controllers into areas.
Once you start programming you will automatically came to know that how it is possible and easier to do than wcf.
good luck...

Related

Using ASP.NET WebApi with a 3 Tier Architecture

I have been trying to get to grips with the use of ASP. NET WebApi recently, I’ve watched a bunch of tutorials and read quite a bit material, but not finding the information I need. This maybe a very basic question, but my idea is to host my webapi with IIS and was aiming for a 3 tier Architecture, something like, Presentation Tier , Business Log and Data Access.
Now I create an MVC 4 project for my presentation tier. But what I am not understanding very well is do I then create another MVC 4 project with a web api template for my business logic and strip out all the controllers, views etc?
Hope I’m making sense.
Thanks for reading.
Whether you should host the WebAPI in a separate ASP.NET application than your MVC project is debatable. Both approaches are correct. For example if you don't want to expose the WebAPI to the public you could host it in some internal network that is accessible only by your MVC application. If you want to expose it to the public then you could host it alongside with your MVC application. So it would really depend whether you want to expose an HTTP API to the public or not.
3 tier architecture doesn't mean (in the general case) SOA (Service Oriented Architecture). If you really need SOA - it's better to have separate projects for API project (Service) and Web UI (Presentation). But if you just need SOA and you don't need REST services (for public access) then it maybe will better to use WCF instead of WebAPI.
Marcel, your MVC is pattern in order to define your presentation tiers, you can also use WebForms, but you have selected MVC,
You must also create Business Layer and DataAccess Layer. these tiers are independent of MVC.
Select MVC just permit you to facilitate unit test (Controller) , facilitate future changing on view's technology, separate businness logic from presentation ...

Flex - Advisable to use multiple web services?

I am developing an application with multiple windows, all using their own web services.
Is it bad practice to use more than one web service per application? If so, what are the disadvantages?
Is it bad practice to use more than
one web service per application?
No! In fact, I don't think I've ever worked on an application that used only one web service.

Using RIA Services directly within an ASP.NET MVC 2.0 project

I am starting a new project which will need a ASP.NET MVC 2.0 website, a Silverlight section and a Windows Phone 7 UI.
My plan was to use WCF RIA Services to create a set of services which would be used in all different UI projects. With the Silverlight project I would use the standard tool integration, the Windows Phone looks like it may have to be WCF Services exposed by the RIA Domain Services, but I'm not sure about the ASP.NET MVC website.
My initial thoughts I would simple reference the class library containing the Domain Services and use them directly. Could this be considered a viable approach to using RIA Domain Services in a ASP.NET MVC website?
Kind Regards
Michael
I know a long time has passed since this question was asked, but since I had to make such a decision, I might as well document it for the benefit of others.
I work in an environment where lots of legacy and new apps co-exist, with the legacy apps being phased out. So we've had to build interoperability between everything from MS Access, to web service end points in C#, VB, Web Forms, MVC 3, even Flex, Reporting Services...the list goes on.
One of the biggest pain points in a multiple-client scenario is the maintenance of interoperability over time. As data, requirements and delivery mechanisms change, keeping things smooth ends up taking a lot of resources.
My approach has been to create one and only one mechanism for reading a given source of data by defining 1) a model, 2) a serialization/deserialization layer and 3) a service layer. All projects that need to use XY_Data must use the XY_Service to get XY_Objects via the XY_Serializer. Direct db calls or stored procs, etc are allowed in the XY_Application. This allows me to drop in replacement DLLs (versioned) with bug fixes and upgrades without restarting anything. I hardly ever do a full publish.
So yes, what you're suggesting will work. I would recommend only that you rigorously enforce the single-source-of-truth and DRY policies both in your data and your APIs.

Asp.net MVC utilising WCF

Looking into developing new startup with potential of hopefully having high volume.
Initial idea was to straight away have MVC talk to WCF services to create our Application Servers.
However after a little contemplating just wondering what benefits would I gain from using WCF services with MVC application?
If performance became an issue we could just keep adding new front web servers instead of application servers.
Enlighten me please, thanks
Don't start using fancy technology for the sake of using it or because it looks cool on paper. You'll have to support it and sometimes find yourself making things overly complicated because of the introduction of something that might not be necessary.
Said that, my current project also uses MVC 2 in combination with WCF. There it was an architectural decision made before I came to the project as they want to spread the tiers on different servers in different domains (outside and inside DMZ). The WCF service can only be called from the server hosting the MVC application so it should increase security.

ASP.NET MVC & Web Services

Does adding a Web Service to my ASP.NET MVC project break the whole concept of MVC?
That Web Service (WCF) depends on the Model layer from my MVC project to communicate with the back-end (so it looks to me like it needs to be part of the MVC solution).
Should I add this to the Controller or Model layer?
It sounds like you should split out your model into its own assembly and reference it from your MVC-application and WCF-application.
YourApp.Data -- Shared model and data access maybe
YourApp.Web -- If you want to share more across your web-apps
YourApp.Web.Mvc
YourApp.Web.WebService
If you want to do WebServices MVC-style maybe you should use MVC to build your own REST-application.
Is there a specific reason you need to add web services to your MVC application? Unless there is a specific reason you should use your controllers in a RESTful manner just as you would a RESTful web service.
Check out this post from Rob Connery for more information:
ASP.Net MVC: Using RESTful architecture
Separating the Model into it's own project is not breaking the "MVC" pattern. First off, it is just that -- a pattern. The intention of the MVC pattern is to clearly delineate between your data, the data handlers, and the presenters and the way you interface between them. The best way to do it is how Seb suggested:
YourApp.Data
YourApp.Web.Mvc
YourApp.Web.WebService
Something that might help you out is the MVC Storefront that Rob Conery put together. Go watch the video's here:
MVC Storefront Video Series
And if you want to look at the actual code in your browser to quickly see how he did it, go here:
MVC Storefront Codeplex Code Browser
I don't think separating the model into it's own assembly has any bearing on whether or not you're using MVC, you still have a model. Where it is is irrelevant surely?
I've had a go at doing this.
See my result at my blog
ps: I don't believe that this will break the MVC concept so long as you think that a web service is the model of a repository because all a web service does is returning a XML dump.
I have added web services to my application and it works well. I don't believe it violates MVC because it is an alternative interface to your model. MVC is not appropriate for web services because web services don't have a view.
Think of web services and databases as one in the same. Under this analogy, I think it makes sense to place your web service ingteractions where you place your database logic.

Resources