Before understanding the difference between Web Service And WCF lets see the background of each.
Web Service in ASP.NET
- A Web Service is programmable application logic accessible via standard Web protocols like Simple Object Access Protocol (SOAP).
- SOAP is a W3C standards technology that uses XML for data encode and transmit application data across the globe.
- It is language as well as platform independent.
- Consumers of a Web Service do not need to know anything about the platform, object model, or programming language used to implement the service; they only need to understand how to send and receive SOAP messages (HTTP and XML).
WCF Service
- WCF is a part of the .NET Framework that provides a unified programming model for rapidly building service-oriented applications that communicate across the web and the enterprise.
- Windows Communication Foundation (WCF) is a framework for building service-oriented applications.
- Using WCF, you can send data as asynchronous messages from one service endpoint to another.
- A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.
- An endpoint can be a client of a service that requests data from a service endpoint.
- The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data.
- WCF is a replacement for all earlier web service technologies from Microsoft. It also does a lot more than what is traditionally considered as "web services".
Features of WCF
- Service Orientation
- Interoperability
- Multiple Message Patterns
- Service Metadata
- Data Contracts
- Security
- Multiple Transports and Encodings
- Reliable and Queued Messages
- Durable Messages
- Transactions
- AJAX and REST Support
- Extensibility
Scenario To Use WCF
- A secure service to process business transactions.
- A service that supplies current data to others, such as a traffic report or other monitoring service.
- A chat service that allows two people to communicate or exchange data in real time.
- A dashboard application that polls one or more services for data and presents it in a logical presentation.
- Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.
- A Silverlight application to poll a service for the latest data feeds.
Major Differences: Following are the major differences between Web services and WCF
Features | Web Service | WCF |
---|---|---|
Hosting | It can be hosted in IIS | It can be hosted in IIS, windows activation service, Self-hosting, Windows service |
Programming | [WebService] attribute has to be added to the class | [ServiceContract] attribute has to be added to the class |
Model | [WebMethod] attribute represents the method exposed to client | [OperationContract] attribute represents the method exposed to client |
Operation | One-way, Request- Response are the different operations supported in web service | One-Way, Request-Response, Duplex are different type of operations supported in WCF |
XML | System.Xml.serialization name space is used for serialization | System.Runtime.Serialization namespace is used for serialization |
Encoding | XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom | XML 1.0, MTOM, Binary, Custom |
Transports | Can be accessed through HTTP, TCP, Custom | Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom |
Protocols | Security | Security, Reliable messaging, Transactions |
Multithreading Support | Can be multithreaded via ServiceBehaviour Class | Cannot be multithreaded |