views:

54

answers:

3

Hi all,

I currently have a web application written by ASP.NET MVC. Now I want to add a web service so that some people can easily build application upon it. Shall I just create the asmx in the MVC Web project or create another project referencing to the Model project? And what's the pros and cons?

Thanks in advance!

+1  A: 

Easy decision - if your MVC Web project depends on the web service at all, keep it in the MVC Web project. If not, create a separate project for the web service with reference to your model.

Keeping projects seperate allows people to read and understand your code more effectively. If your service makes use of your model, but is not part of that model, than it should definitely be a standalone project with reference to the model. This is clean design.

jscharf
Thanks! If we separate the web service from the web application, we need to host them separately, but they perform same logic on the same data. Does it look bias for the client?
Roy
A: 

for my opinion I would do something like this in my solution

solution.Model           -- the model that reflects your db,
solution.Repository     
solution.MVC             -- your model will be the refined Model, referencing the solution.Model
solution.Test
solution.WebService      -- referencing solution.Model

I keep my Model outside my MVC Web application and just put the refined ViewModels in my MVC Model folder. I don't know much about pro's and con's but this is just a better way of doing it for me.

Doing this, you can use your Model anyway you want. Maybe you want to use it for WebService as what you ask. Or for another Application. You just reference your Model project to other projects that you need them.

rob waminal
Thanks, rob! I also have a Model project as you mentioned. The only reason prevent making a new webservice is that I think separately host the web application and web service is a little bias. How do you host your web application and web service? thanks!
Roy
both application and webservice can be hosted separately. They are just using the dll produced by the Model project.
rob waminal
A: 

I would look for Odata -> WCF Data Services formaly know as "Astoria". If you are using for example linq-to-sql or EF you can make your data in a restful manner availale and provide a basic api... You can define your endpoint like you do in WCF because the underlying service is based on WCF. And I would use a different namespace...

Website http://msdn.microsoft.com/en-us/data/bb931106.aspx

Beginners guide with videos http://msdn.microsoft.com/en-us/data/ee720180.aspx

open data format http://www.odata.org/

server info