114

What is the difference between them?

When would I opt for one over the other?

Developer
  • 17,809
  • 26
  • 66
  • 92
  • Check out the other discussion here for more info... http://stackoverflow.com/questions/50114/wcf-wtf-does-wcf-raise-the-bar-or-just-the-complexity-level – Kwal Dec 08 '08 at 23:49

6 Answers6

69

This answer is based on an article that no longer exists:

Summary of article:

"Basically, WCF is a service layer that allows you to build applications that can communicate using a variety of communication mechanisms. With it, you can communicate using Peer to Peer, Named Pipes, Web Services and so on.

You can’t compare them because WCF is a framework for building interoperable applications. If you like, you can think of it as a SOA enabler. What does this mean?

Well, WCF conforms to something known as ABC, where A is the address of the service that you want to communicate with, B stands for the binding and C stands for the contract. This is important because it is possible to change the binding without necessarily changing the code. The contract is much more powerful because it forces the separation of the contract from the implementation. This means that the contract is defined in an interface, and there is a concrete implementation which is bound to by the consumer using the same idea of the contract. The datamodel is abstracted out."

... later ...

"should use WCF when we need to communicate with other communication technologies (e,.g. Peer to Peer, Named Pipes) rather than Web Service"

Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30
rbrayb
  • 46,440
  • 34
  • 114
  • 174
  • 2
    For any new project based on SOA approach, Developer should select WCF over webservices. Because it gives the flexibility and scalibility for future use. There is only one exception: if the client doesn't support communication with wcf services i.e. Flash AS2. – Lalit Apr 21 '10 at 10:53
  • WCF 1) It is a multi-layered architecture 2) It provides a single unified platform (interoperable) or framework to build Service Oriented Application to communicate using a variety of network protocols. 3) WCF provides better security and reliability as compared to web services or ASMX services 4) Support for Plain XML, Ajax and REST Web Service 1) It is simple 2) Write a function and hook it with the [WebMethod] attribute and it is ready to give service – Arun Banik Sep 03 '14 at 12:03
  • As answered from Joe -> The Article ist replicated on http://www.codeproject.com/Articles/139787/What-s-the-Difference-between-WCF-and-Web-Services – Bernhard Apr 18 '16 at 14:26
33

From What's the Difference between WCF and Web Services?

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".

WCF "web services" are part of a much broader spectrum of remote communication enabled through WCF. You will get a much higher degree of flexibility and portability doing things in WCF than through traditional ASMX because WCF is designed, from the ground up, to summarize all of the different distributed programming infrastructures offered by Microsoft. An endpoint in WCF can be communicated with just as easily over SOAP/XML as it can over TCP/binary and to change this medium is simply a configuration file mod. In theory, this reduces the amount of new code needed when porting or changing business needs, targets, etc.

ASMX is older than WCF, and anything ASMX can do so can WCF (and more). Basically you can see WCF as trying to logically group together all the different ways of getting two apps to communicate in the world of Microsoft; ASMX was just one of these many ways and so is now grouped under the WCF umbrella of capabilities.

Web Services can be accessed only over HTTP & it works in stateless environment, where WCF is flexible because its services can be hosted in different types of applications. Common scenarios for hosting WCF services are IIS,WAS, Self-hosting, Managed Windows Service.

The major difference is that Web Services Use XmlSerializer. But WCF Uses DataContractSerializer which is better in performance as compared to XmlSerializer.

Community
  • 1
  • 1
Joe
  • 2,381
  • 1
  • 17
  • 17
  • 2
    Random note: A big difference of DataContractSerializer and XmlSerializer is that DCS *requires* field ordering - which is why I don't use DCS for non-transient serialization or contracts! Thus it's possible to break a service used by clients not using the fixed ordering when moving to DCS (or moving to DCS but in a different order than was previously used). Granted, this should be expressed in the Schema, but .. – user2246674 Jul 11 '13 at 19:52
  • 1
    Also, **please cite/link sources and indicate extracts** and/or take the original information and write something new with it. It's rude to steal. I've added the link for you, but make sure to give credit where it is due! (I would downvote on this basis, if I could downvote at all.) – user2246674 Jul 11 '13 at 19:55
31

Web Service is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS.

WCF is also based on SOAP and return data in XML form. It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ. The main issue with WCF is, its tedious and extensive configuration. It is not open source but can be consumed by any client that understands xml. It can be hosted with in the applicaion or on IIS or using window service.

CSK
  • 777
  • 7
  • 17
  • 2
    WCF can also receive/send http request/responses in JSON format, and without using SOAP/schemas (nowadays?). – Efrain Mar 11 '16 at 13:19
  • Point of detail: SOAP supports HTTPS. The encoding happens at the transport layer, so the client is agnostic to it - the client makes XML requests and gets XML responses, and it neither knows nor cares as to whether along the way it was plain-ol-http or encrypted-https. – Jinlye Aug 08 '18 at 11:38
16

Basic and primary difference is, ASP.NET web service is designed to exchange SOAP messages over HTTP only while WCF Service can exchange message using any format (SOAP is default) over any transport protocol i.e. HTTP, TCP, MSMQ or NamedPipes etc.

Imran Ghani
  • 188
  • 1
  • 3
5

What is the difference between web service and WCF?

  1. Web service use only HTTP protocol while transferring data from one application to other application.

    But WCF supports more protocols for transporting messages than ASP.NET Web services. WCF supports sending messages by using HTTP, as well as the Transmission Control Protocol (TCP), named pipes, and Microsoft Message Queuing (MSMQ).

  2. To develop a service in Web Service, we will write the following code

    [WebService]
    public class Service : System.Web.Services.WebService
    {
      [WebMethod]
      public string Test(string strMsg)
      {
        return strMsg;
      }
    }
    

    To develop a service in WCF, we will write the following code

    [ServiceContract]
    public interface ITest
    {
      [OperationContract]
      string ShowMessage(string strMsg);
    }
    public class Service : ITest
    {
      public string ShowMessage(string strMsg)
      {
         return strMsg;
      }
    }
    
  3. Web Service is not architecturally more robust. But WCF is architecturally more robust and promotes best practices.

  4. Web Services use XmlSerializer but WCF uses DataContractSerializer. Which is better in performance as compared to XmlSerializer?

  5. For internal (behind firewall) service-to-service calls we use the net:tcp binding, which is much faster than SOAP.

    WCF is 25%—50% faster than ASP.NET Web Services, and approximately 25% faster than .NET Remoting.

When would I opt for one over the other?

  • WCF is used to communicate between other applications which has been developed on other platforms and using other Technology.

    For example, if I have to transfer data from .net platform to other application which is running on other OS (like Unix or Linux) and they are using other transfer protocol (like WAS, or TCP) Then it is only possible to transfer data using WCF.

  • Here is no restriction of platform, transfer protocol of application while transferring the data between one application to other application.

  • Security is very high as compare to web service

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
Ali Azam
  • 2,047
  • 1
  • 16
  • 25
3

The major difference is time-out, WCF Service has timed-out when there is no response, but web-service does not have this property.

NTDLS
  • 4,757
  • 4
  • 44
  • 70