Jan
18
2012
ASP.net // C# // WCF

C#.net : Difference between Webservice and WCF Service

What is the difference between webservice and wcf service? is a very common question in almost every interviews. This is one of the most important topic because programmer should know when to use asp.net web service and when to use wcf service. We should know what is webservice and what is wcf? In other article i have already explained about web service and what is wcf service. The summary of the two is given below.

What is Webservice?

According to web definition from WIKI –

“…A web service is a method of communication between two electronic devices over World Wide Web. It is a software function provided at a network address over the web with the service always on as in the concept of utility computing.”

Web service is a mechanism that provides data as a service/response over the http protocol on request of some other programs.

What is WCF service?

Windows Communication Foundation (WCF) is a often use to develope and deploy network distributed services based on the principles of Service Oriented Architecture (SOA). The fundamental characteristic of WCF is Interoperability. This gives you more manageable approach to create and consume web services.

From the previous posts, we learn to create a WCF service, consume wcf service, self-host wcf service and other various activities.

C#.Net - Difference between Webservice and Wcf
C#.Net – Web Service Vs WCF service

In this c# tutorial we are going to see the difference between ASP.net web service and WCF service. The table below shows the difference between webservice and wcf. By the end of this article i believe you will completely familier with webservice vs wcf service.

 

Difference between Webservice and WCF service

Sr. No Features ASP.net Web Service WCF Service
1 File Format/Extension ASP.net web services uses .asmx as a file extension. WCF web service uses .svc as a file extension.
2 Hosting ASP.net Web service can be hosted in IIS. As well as ASP.net WebService can be hosted outside of IIS like ASP.net web service can be hosted in a Windows Service. WCF service is flexible because it can be hosted in IIS, Windows Activation Services(WAS), Managed Windows Services and It also supports Self-Hosting.
3 Transport Protocols/Binding ASP.net Web service supports HTTP & TCP protocols along with custom binding. WCF service supports HTTP, WS-HTTP, TCP, Custom, Named Pipes, MSMQ & P2P(Point to Point) etc.
4 Data Transformation It uses XML serializer for Data Transformation. WCF service uses DataContractSerializer for Data Transformation.
5 Serialization NameSpace System.XML.Serialization System.RunTime.Serialization
6 Supported Operations The supported operations are only One-Way and Request-Response type. The supported operations includes One-Way, Request-Response and Duplex.
7 Encoding It uses following encoding mechanisms -
XML1.0, MTOM (Message Transmission Optimization Mechanism), DIME (Direct Internet Message Encapsulation)
It uses following encoding mechanisms -
XML1.0, MTOM, Binary
8 WebMethods and DataContract Uses WebMethods to translate .Net FW types in to XML.

  • [WebService] attribute has to be added to into the class.
  • [WebMethod] attribute represents the method exposed to the client.
Uses DataContractAttributes and DataMemberAttribute to translate .Net FW types in to XML.

  • [ServiceContract] attribute has to be added to into the class.
  • [OperationContract] attribute represents the method exposed to the client.
9 Messaging Asp.Net web service supports only SOAP(Simple Object Access Protocol) as messaging service. WCF service can send/receive message through any transport protocol message format. However, by default it uses SOAP for communication.
10 Security This is not much secured as compared to WCF. It is less secured to protect data between Server and Client. Certificates can protect the data but it is very complicated to use Certificates. For security, normally we use UserName/Password. As compared to ASP.net web service, WCF services are more secured. WCF does not need IIS to run, it can run as a System Service on the Server, using a command ambient. We can say that WCF is a service and not a Web Service.
11 Performance Performance wise web services are slower than WCF service. WCF services are than WebService. The performance measures in terms of xml serialization.
12 Exception Handling This returns all unhandled exceptions to the client as SOAP faults. WCF does not returns unhandled Exceptions to the client as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to the Client for the purpose of debugging.
13 Limitations
  • Hash Table cannot be serialized.
  • Only public properties/fields can be serialized
  • The DataContractSerializer translate the Hash table into the XML.
  • Public/Private properties/fields can be serialized.

I hope you enjoyed the article that explains the difference between webservice and wcf. If you find this article helpful, then could you please share the article on your social media?

Following articles might be of your interest…

About the Author: Ashish Ramteke

Ashish Ramteke is a Software Professional, Part time blogger and founder of C# Tutorials, a popular blog on C#.Net. Ashish is having 6 years of work experience and an engineering degree in Computer Science and Engg.

12 Comments+ Add Comment

  • Great Job….

  • I think this tabular form explains a lot. Thanks for the info Ashish.

  • thank u Ashish,it will help me a lot..

  • The first thing in this site is cool look, which attract the readers…

  • Nice article

  • Brilliant article :)

  • Great shot. and ease to learn.

  • Thanks a lot for sharing this info

  • It is really helpful

  • Thanks alot..

  • nice… keep it up

  • Very Nice article and informational blog.

Leave a comment