Asp.Net MVC and Web Services

I have an existing Asp.Net MVC website, and I would also like to provide a web service from the same domain.

What is the best approach to creating a web service in this scenerio?

Add to this project or ...?

+6
web-services asp.net-mvc
source share
3 answers

You should be able to add the WebService file directly to the MVC project. Right-click on the solution and select a new item, then select a web category and there should be a web service at the bottom of the list.

Do not forget to check if the route is spent on the web service.

In this way, the web service can access the same model classes as the MVC application.

+3
source share

You can add a web service to the project in the same way as in regular ASP.NET web applications, however MVC is basically a web service. You can create a controller that processes all the requests that you want your web service to handle.

With the advent of MVC, quite often you have to make applications that ever load a view once, and then use AJAX and client scripts for almost the entire life of the application. Your AJAX calls simply click on action methods for your products, and then use the delicious JSON information to analyze the data and use it.

In my opinion, creating a web service as a controller instead of using [WebMethods] is much simpler and much more fun!

+3
source share

First, the question: "What do we mean by a web service?" It can mean anything: from an MVC page that responds using XML, JSON, or some other consistent format for full-sized SOAP and WS- * burdened nightmares.

In any case, the best place to start is with WCF support services - they work very well with MVC, including routing.

Cold kids use openrasta .

+1
source share

All Articles