Josh
Josh

Reputation: 259

Model v/s Controller - wcf communication

In a typical ASP.net mvc application which layer should talk to WCF service ? Is it model or the controller ? Which approach is benefical ?

Thanks Josh

Upvotes: 1

Views: 183

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

Normally that should be the data layer. The controller then talks to the data layer. Whether the data is stored inside a database, flat file or coming from a remote web service, the data layer should be responsible for retrieving and manipulating it. You could then of course have different implementations for the data layer depending on where your data is coming from.

You need to have an abstraction (interface) over the operations you need to perform with the data and then have your Controller take this interface as constructor argument. For the case of WCF, you could directly use the interface that was created for you when you imported the definition of the WCF service - the client side proxy service contract.

Here's a similar answer I wrote with an example.

Upvotes: 2

Related Questions