Sunday, February 24, 2013

Comparison of Web Service API implementation methods in ASP.NET

In ASP.NET, there are several options to implement Web Service API. Below is a quick summary:

1) XML Web Service -- SOAP
When: .NET Framework 1.0 (Feb. 2002)
What: simple service call using SOAP, XML, HTTP and WSDL.
Development tool: ASP.Net WebMethod attribute, Web Service class, auto-generated asmx description
Pros: very simple for simple service
Cons: not flexible because client has to understand SOAP. the overhead of SOAP message and XML encoding.

2) WCF -- Service Oriented Architecture (SOA)
When: .NET Framework 3.0 (Nov. 2006)
What: SOA, typically SOAP and other protocols/services/message types (XML, JSON etc).
Development tools: Visual Studio templates, classes, configurations
Pros: very flexible (duplex communication, messaging), the focus of Microsoft for general distributed SOA
Cons: heavy in size and configuration due to its flexibility

3) Web API -- RESTful API
When: was part of WCF but was combined with ASP.NET MVC 3.0  Web API (Jan 2011)
What: RESTful API over HTTP, message types are usually XML and JSON, but customizable
Development tools: many tools in both server and client side.
Pros: the current industry trend, simple and flexible.
Cons: more complex than XML Web Service because of the routing design

Which to use? The XML Web service is deprecated. The choose is between WCF and Web API. The article (http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx) summarized the debate as below:

  • For resource-oriented services over HTTP, use Web API
  • Others (messaging, duplex communication, TCP/UDP communication), use WCF
For Web Service development, the design of URI and API interface is a big challenge. If you application needs a set of Web API to access a data set, OData (http://www.odata.org/) standardized the APIs for this specific area.

Both WCF and Web API have very good support for OData development. It is a good start for you to develop data access API.