Henry Aung Henry Aung - 4 years ago 146
reST (reStructuredText) Question

Using ASP.NET MVC as Web Service

Does anyone have experience using ASP.NET MVC project as a Web Service?

i.e. using ASP.NET MVC without Views, so other applications can use the URL to GET or POST to the actions in the Controller.

Has anyone used it? If so, are there any drawbacks for not using Web Service project instead?

Thank you all in advance!

Answer Source

It really depends on the kind of application you're writing. I would actually argue the inverse of LukLed's position - SOAP-based services are better suited for internal clients when you want to support things like Windows Authentication, or different protocols like TCP or MSMQ.

Using a more web-style of GETs and POSTs around specific "resources" starts to get you into the REST architectural style. This technique has a few distinct advantages to me:

  • The response is usually smaller, particularly when using lightweight formats like JSON
  • Because of the simplicity of the requests and responses, this makes it much easier to use in mobile / native applications (see Twitter's API, for example)
  • The service you create can be self-describing and discoverable, because you can link to other parts of your API just like normal web pages.

One article that particularly helped me understand the tradeoffs here is Martin Fowler's "Steps Toward the Glory of REST." That being said, it may or may not be the right fit for your application.

If you do choose to build a more REST-based service, definitely consider using the ASP.NET Web API built into MVC4 as others have mentioned. It's currently in beta, but Microsoft felt good enough about it to give it a go-live license.

UPDATE:

Since ASP.NET core, ASP.NET web API has been integrated into MVC 6 project. https://wildermuth.com/2016/05/10/Writing-API-Controllers-in-ASP-NET-MVC-6

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download