Search code examples
asp.netasp.net-mvcweb-servicessoapado.net-entity-data-model

MVC with web services


I'm working on building an application that's based on SOA. I have bunch of business services that I should make them available as components to another applications (so I'll use web services -SOAP-).

The application presentation layer is MVC.

1- Model: Contains DataBase methods (ORM is used).

2- Controller: Contains calls to the model methods as well as methods to handle simple view actions.

3- View: Contains rendering content only.

So, can you give me a simple scenario how can I combine web service with my MVC application, my suggestion is to separate the model as web services, is that right?


Solution

  • I'd tackle it this way: (YMMV)

    • Build a data tier assembly housing all your data access. Call it the DAL. It will contain all data access methods. This will enable re-use, but also allow for methods used by one application below. This is where your EF model can live.

    • Build 2 web projects: MVC and web services. Each will implement business logic to satisfy their respective requirements. They'd reference and call into the DAL as needed for data access. As you noted, they're both presentation-tier services. One has a user interface, the other is a communication endpoint for remote web service consumers.

    • Deploy both onto an application server as needed. Suggest creating 2 applications/sites in IIS - (i.e. "Web" and "WebServices"). This separation of applications ensures that one can be changed/downtimed/versioned without effecting the other.

    • The MVC project/app will still have its Models, Views and Controllers as per normal. The biggest change here is that the Models would be used only for ViewModels as needed. It would contain any business logic to satisfy the UI requirements. Its controller methods would call the appropriate DAL public methods as needed.

    • The web services project/app would be able to be changed independently as needed, while the data access would remain.