Difference between WCF and Web service

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service. Following points provides detailed difference between them.

Web Service:

  • Hosting -It can be hosted in IIS.
  • Programming -[WebService] attribute has to be added to the class. Continue reading

Features of WCF

WCF includes the following set of features:

Service Orientation 

One consequence of using WS standards is that WCF enables you to create service oriented applications. Service-oriented architecture (SOA) is the reliance on Web services to send and receive data. The services have the general advantage of being loosely-coupled instead of hard-coded from one application to another. A loosely-coupled relationship implies that any client created on any platform can connect to any service as long as the essential contracts are met. Continue reading

Windows Communication Foundation

  • Windows Communication Foundation (Code named Indigo) is a programming platform, runtime system and set of APIs for building, configuring and deploying network-distributed services or service-oriented applications.
  • It is unified programming model provided in .Net Framework 3.0. WCF is a combined feature of Web Service, Remoting, MSMQ and COM+.
  • WCF provides a common platform for all .NET communication.
  • 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 designed using service oriented architecture principles to support distributed computing where services have remote consumers.
  • Clients can consume multiple services and services can be consumed by multiple clients.
  • Services are loosely coupled to each other.
  • Services typically have a WSDL interface (Web Services Description Language) that any WCF client can use to consume the service, regardless of which platform the service is hosted on.
  • WCF implements many advanced Web services (WS) standards such as WS-AddressingWS-Reliable Messaging and WS-Security.
  • With the release of .NET Framework 4.0, WCF also provides RSS Syndication Services, WS-Discovery, routing and better support for REST services.
  • A few sample scenarios include:
  • 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.
  • While creating such applications was possible prior to the existence of WCF, WCF makes the development of endpoints easier than ever. In summary, WCF is designed to offer a manageable approach to creating Web services and Web service clients.

Web Services Vs WCF

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