I’m developing an MVC3 application for a university project. I am hoping to use WCF as the web service to be able to connect to a remote database, using stored procedures. I don’t really have the time to learn Entity Framework at present.
My question is where should the stored procedure names be held? Should the MVC model pass the stored procedure names to the WCF service along with the values, etc or should the model simply call a method within the WCF service, which will hold the stored procedure name and handle that aspect?
Thanks.
In the data access layer which is located in your WCF service project. The ASP.NET MVC 3 application only invokes a method on this service. Remember that an ASP.NET MVC application doesn’t know what a database is and even less what a stored procedure is. An ASP.NET MVC application works only with Models, Controllers and Views.
So in your WCF service project you will have a service contract:
then you could have an implementation in the WCF service that will go and fetch the data wherever it is stored (in your case that would be a SQL database and the way to fetch this data is to invoke a stored procedure):
Obviously this will tightly couple your service layer with a given data access technology. In order to decouple it you could bring another level of abstraction between the service and the actual data access:
and the actual stored procedure call will be performed in the specific SQL implementation of the repository that will be injected into your service by your DI framework.
In the ASP.NET MVC application you will only consume the WCF service from the strongly typed client proxy that was generated for you when you added the service reference.