1.Hosting: Webservice can be hosted in IIS while WCF can be hosted in
IIS,Self-hosting,Windows service,windows activation service etc.
Thus WCF is more flexible and useful than webservice.
2.Binding: Webservice supports only http binding while WCF supports
HTTP,TCP,MSMQ Bindings etc.Again due to this reason WCF is more flexible
3.Duplex communication: Web service supports one way and request response operations
while WCF supports one way ,request response and
Duplex communication as well.
In a client server scenario a duplex WCF service is a service
where the server can send messages to the client
without the client requesting them.
In the scenarios when an event taking place on the server
should send a message to your client we should use Duplex WCF service.
For example a third party application sending message to your
service and your service must inform itas client
after receiving third party message.
4.Serialization : In web service System.Xml.serialization is used for
serialization while in WCF System.Runtime.Serialization
namespace ( DataContractSerializer class) is used for serialization.
This serializatiobn used in WCF gives better performance.
System.Xml.serialization is called XML serialization
while System.Runtime.Serialization namespace ( DataContractSerializer class for WCF)
that works like Binary serialization.
A.Binary serialization is faster than XML serialization
because Binary serialization writes raw data but XML serialization
needs formatting of data as per XML.
B.In binary serialization All members will be serialized
but in XML serialization Only Public fields or Properties can be Serialized
Also in XML serialization Only the classes which implement
IEnumerable interface can be Serialized.
5.Encoding : Web service supports mainly XML and Custom Encoding
but WCF supports XML,Custom and Binary Encoding as well.
An Encoding is a set of rules to present messages on the wire.
In other words Encoding is a process of
converting a message into an array of bytes.
Encoding should not be confused with serialization
Serialization defines how the .NET object maps to XML,
while Encoding defines how the XML is written out to a stream of bytes
6.Class Attribute : In web service the attribute used for service class is
[WebService] while in WCF the attribute used for
service class is [ServiceContract]
7.Logging :WCF has an integrated Logging mechanism
that enables us to log traces without writing code for it.
Web service does not have this facility.
changing the configuration file settings in WCF provides logging functionality.
To use Integrated logging mechanism of WCF you need
to enable message logging in WCF and enable ASP.NET tracing.
8.Method Attribute :In web service the attribute used for service method is
[WebMethod] while in WCF the attribute used for
service method is [OperationContract]
9.Security :WCF has more security options than web service
The options for securing ASP.NET Web services
are those for securing any IIS application but the options for securing
WCF applications are independent from the facilities of IIS because
it had to cater to other (tcp ,mamq and of course http) protocol
other than http from security perspective
so WCF has all the security options of webservice
and additionally it has other security options
of other type of hosting and or underlying implementation(tcp msmq etc).
Also for mostly used bindings WCF provides default security
which can be trusted like message security on WSHTTPbinding.
10.Performance:WCF is faster than ASP.NET Web Services
Because The DataContractSerializer(Binary like) used in WCF has better performance advantages
over XML serialization used in webservice so WCF service is faster than ASP.NET webservice
11.Transaction :WCF supports Atomic Transactions while Webservice does not
support atomic transaction. WS-Atomic protocol is used to handle transactions in WCF
Using this protocol different WCF services hosted
on different servers togather can participate in transaction.
12.Session :WCF can maintain Session easily while
in webservice lots of code has to be written for that.
Below is a sample WCF class with Required Session Mode
public interface ICalculatorSession
13.Exception Handling :
Web services Unhandled exceptions are returned to the client as SOAP faults.
WCF Services unhandled exceptions are not returned to clients as SOAP faults.
We need to do a configuration setting for the unhandled exceptions
to return to clients for debugging.
14.AJAX and JSON Support:WCF provides AJAX and JSON(java script object notation)
integration support but web service does not have it.
Thus WCF services can expose operations to AJAX clients.
accessing these WCF services using HTTP requests