Difference Between WCF and Web Services
WCF is a replacement for all earlier web service technologies. Microsoft develops it. It supersedes what is traditionally considered as “web services”. Web Service is based on SOAP that returns data in XML form. It just supports the HTTP protocol. It is also not open source and can be consumed by any client who understands XML. It can only be hosted in IIS.
What is WCF?
WCF is based on SOAP and returns data in XML form. It is an extension of the web service (ASMX) and supports various protocols like HTTP, HTTPS, TCP, Named Pipes, MSMQ, etc. WCF has an issue with its tedious and extensive configuration. It is not open source but can be used by any client who understands XML. It can be hosted on multiple platforms as in the application or on IIS, or using window service.
In what scenarios must WCF be used?
- For making business transactions, WCF provides us with a secure server.
- Two or more people can communicate and also exchange data in real-time using a chat service built on top of WCF.
- A dashboard application that polls one or more services for information and presents it logically.
- Exposing a workflow that is implemented using Windows Workflow Foundation as a WCF service.
What is a Web Service?
As discussed above, Web Services work in a stateless environment. It can only be accessed over HTTP. WCF services can be hosted in different types of applications. Therefore, unlike Web Services, WCF is more flexible.
WCF can be hosted in various scenarios. Such scenarios include services such as WAS, IIS, Self-hosting, Managed Windows Service, etc.
Head To Head Comparison Between WCF and Web Services(Infographics)
Below is the top 9 difference between WCF vs Web Services
Key Differences Between WCF and Web Services
Both are popular choices in the market; let us discuss some of the major difference:
- While transferring data from one application to other application, Web service uses HTTP protocol only. On the other hand, for transporting data, WCF supports more protocols compared to ASP.NET web services. Apart from sending messages using HTTP, WCF also supports Transmission Control Protocol (TCP), Microsoft Message Queuing (MSMQ) and named pipes.
- WCF is architecturally more robust than Web Service.
- XmlSerializer is used in Web Services. WCF uses DataContractSerializer, which is better when compared to XmlSerializer in terms of performance.
- When communicating between multiple applications developed on different platforms, we use WCF. Using WCF is the only possible for transferring data if we are transferring data from the .NET platform to any other application running on other operating systems such as Unix or Linux.
- Security in WCF is very high when compared to web service.
WCF vs Web Services Comparison Table
Below is the 9 topmost comparison between WCF vs Web Services
The basis of comparison |
WCF |
Web Services |
Introduction Version | WCF service got introduced with .NET version 3.0. | Web service exists in a .net framework from version 1.0. |
Protocol for receiving and sending messages | WCF services use SOAP by default, but the messages can be in any format and conveyed by using any transport protocol such as WS- HTTP, TCP, Named Pipes, HTTP, HTTPs, MSMQ, P2P(Point to Point) etc. | ASP.NET Web services can send and receive messages using SOAP over only HTTP or HTTPS. |
FILE ExtEnsion | Wcf services have a “.svc” extension. | Web services have a “.asmx” extension. |
Directive | The svc page uses the “ServiceHost” directive. | The asmx page uses the “WebService” directive. |
Serialization technique | It uses DataContractSerializer in System.RunTime.Serialization namespace for serialization. | For serialization, ASP.NET Web services are based on the XmlSerializer in System.XML.Serialization namespace. Some of the limitations of XmlSerializer are:
|
Hosting mechanism | WCF services can be hosted in multiple platforms such as IIS, Windows Activation Services(WAS), Managed Windows services or self-hosting etc. | ASP.net Web service can only be hosted in IIS. |
unhandled Exception handling | Exceptions that are unhandled are not returned to clients as SOAP faults. | Exceptions that are unhandled are returned to clients as SOAP faults in ASP.NET Web services. |
Multi-Thread Support | Multi-threading is supported by WCF services. | There is no support for multi-threading in web services. |
Performance | WCF is faster when compared to Web Services | Since web services use serializers, therefore they are slower than WCF services in terms of performance. |
Example Of WCF vs Web Services
Below are the example of WCF vs Web Services are as follows:
Web Services
The following code snippet shows us how to develop a service in Web Service.
[WebService]
public class MyService
{
[WebMethod]
public SumClass SumOfNums(string JsonStr)
{
var ObjSerializer = new JavaScriptSerializer();
var ObjSumClass = ObjSerializer.Deserialize<SumClass>(JsonStr);
return new SumClass().GetSumClass(ObjSumClass.First, ObjSumClass.Second);
}
}
public class SumClass
{
public int First, Second, Sum;
public SumClass GetSumClass(int Num1, int Num2)
{
var ObjSum = new SumClass
{
Sum = Num1 + Num2,
};
return ObjSum;
}
}
WCF
The following code snippet shows us how to develop a service in WCF.
ServiceContract]
blic class MyService : WebService
{
[OperationContract]
public SumClass SumOfNums(string JsonStr)
{
var ObjSerializer = new JavaScriptSerializer();
var ObjSumClass = ObjSerializer.Deserialize<SumClass>(JsonStr);
return new SumClass().GetSumClass(ObjSumClass.First, ObjSumClass.Second);
}
}
[DataContract]
public class SumClass
{
[DataMember]
public int First;
[DataMember]
public int Second;
[DataMember]
public int Sum;
public SumClass GetSumClass(int Num1, int Num2)
{
var ObjSum = new SumClass
{
Sum = Num1 + Num2,
};
return ObjSum;
}
}
Conclusion
From the above discussion, WCF service is definitely an advanced technology that Web service. WCF is faster than web service in terms of performance. WCF provides better security, supports various protocols as well as message formats. The only hectic area of WCF for developers is its configuration portion. However, this problem also got solved with WCF4.0 by introducing default configuration settings. It is noticed that up to.NET3.5, the visual studio, provides a direct template for web service. From.NET4.0, we do not get any direct template for web service. Hence, we need to create a web application & add a web service to it.
Recommended Articles
This has been a guide to the top difference between WCF vs Web Services. Here we also discuss the key differences with infographics and comparison table. You may also have a look at the following articles to learn more.
- Ubuntu vs Windows 10
- Mobile App vs Websites
- Sleep mode vs Hibernate
- Microsoft Azure vs Amazon Web Services
4 Online Courses | 11 Hands-on Projects | 65+ Hours | Verifiable Certificate of Completion
4.5
View Course
Related Courses