3

I have a web application in MVC 3 (3-tier with a Data Access Layer) that I'd like to extend to native iPhone and Android etc... as presentation devices.

Can I just use the same controllers with some modifications or is it better to organize the access logic into a WCF service?

What are you recommendations in terms of good scalability and performance?

Max Alexander
  • 5,471
  • 6
  • 38
  • 52

2 Answers2

1

For scalability, it would be better to have your business logic in a service that your UI (MVC site, iPhone app, android app) simply calls. I personally suggest using ServiceStack over WCF, as it simplifies your calls down to POCO objects. This will help for scalability, as well as maintenance as it separates your concerns much clearer (I suggest you read up on the SOLID principles). If you need to make changes to your UI, those changes will not affect your business logic (which would have caused your iPhone app to change possibly)

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
  • That SOLID principles article is pretty hard to follow, but I'm really interested, do you have a suggestion on other reads? – Max Alexander Apr 06 '12 at 04:57
1

It all depends. You can certainly go the route Justin recommends. There's a lot of work in that, though.

MVC4 has WebAPI, which gives you RESTful services from within an MVC controller-like environment. This allows you to add a service layer to your MVC app with minimal effort.

For anything large scale, you should probably go with a full WCF implementation.

FYI, MVC4 is in beta, but there is a go-live license, and you can install WebAPI without installing MVC4, it's availble via nuget.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • So if I currently have a Unit Tests Project, Domain Project, and MVC 3 Web Project, I assume that adding the WCF, I'd insert it between the Domain and the MVC. Are there any good guidelines with a 4-tier architecture this way? – Max Alexander Apr 06 '12 at 04:59
  • @MaxAlexander - That depends. You could just integrate the WCF service layer into your domain. If that's the only way to access it, then that's probably the best choice. However, if you want your domain to be a stand-alone model, then yes. Unit tests are not part of the "tiers". – Erik Funkenbusch Apr 06 '12 at 16:28
  • Oh okay. So if the database is connected to entities in the domain model, and a repository is used to manipulate domain entities, the WCF is used as communication port with repository methods. Then assuming that MVC specifically uses strict view models, what's the best way to connect MVC with the WCF? – Max Alexander Apr 06 '12 at 17:05
  • @MaxAlexander - http://stackoverflow.com/questions/8549975/how-to-build-a-wcf-to-asp-net-mvc-client-architecture-using-json-format-endpoi – Erik Funkenbusch Apr 06 '12 at 17:09
  • Right but what if I wanted to expose SOAP objects between WCF and MVC? Should the WCF communicate with it's clients specifically in view models? Or another intermediate model? I don't want the clients knowing what the domain models are (that's good practice isn't it?) – Max Alexander Apr 06 '12 at 17:20
  • @MaxAlexander - If you use SOAP then it's just a matter of adding a web reference via the WSDL. I'm not sure what you mean about the View Models. WCF would expose whatever objects it needs to, the client worries about what to do with them. So your MVC would read the soap objects and either copy them to a View Model use them directly (if your view is exactly the same as the soap objects model, you can use a "buddy class" to map the validation attributes as metadata.) – Erik Funkenbusch Apr 06 '12 at 17:26