DZone
Integration Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Difference Between Web Service and WCF

Difference Between Web Service and WCF

Santhakumar Munuswamy user avatar by
Santhakumar Munuswamy
CORE ·
Feb. 20, 15 · Integration Zone · Interview
Like (0)
Save
Tweet
11.03K Views

Join the DZone community and get the full member experience.

Join For Free

Overview
My previous article provided an Introduction to WCF  (Windows Communication Framework). Now we will discuss the differences between Web Services and WCF concepts.

Web Services (ASMX)
Web Services are used to send/receive messages using the Simple Object Access Protocol (SOAP) via HTTP only. 

It is available in the namespace “System.Web.Services. WebService Class” with a constructor, methods, prosperities and events.

Code

using System;    
using System.Collections.Generic;    
using System.Web;    
using System.Web.Services;    
    
namespace HelloWorldServices    
{    
    /// <summary>    
    /// Summary description for Service1    
    /// </summary>    
    [WebService(Namespace = "http://tempuri.org/")]    
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    
    [System.ComponentModel.ToolboxItem(false)]    
    public class Service1 : System.Web.Services.WebService    
    {    
    
        [WebMethod]    
        public string HelloWorld()    
        {    
            return "Hello World";    
        }    
    }    
}  

WCF
WCF is used to exchange messages using any format via any transport protocol like HTTP, TCP/IP, MSMQ, Named Pipes and and so on. Its default format is SOAP.

Note: Microsoft Message Queuing (MSMQ) is a messaging queue services developed by Microsoft.
Simple Object Access Protocol (SOAP) is a messaging protocol developed by W3C.

Code: IService1.cs

using System;    
using System.Collections.Generic;    
using System.Linq;    
using System.Runtime.Serialization;    
using System.ServiceModel;    
using System.ServiceModel.Web;    
using System.Text;    
    
namespace HelloWorldWCFService    
{    
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.    
    [ServiceContract]    
    public interface IService1    
    {    
    
        [OperationContract]    
        string GetData(int value);    
    
        [OperationContract]    
        CompositeType GetDataUsingDataContract(CompositeType composite);    
    
        // TODO: Add your service operations here    
    }    
    
    
    // Use a data contract as illustrated in the sample below to add composite types to service operations.    
    [DataContract]    
    public class CompositeType    
    {    
        bool boolValue = true;    
        string stringValue = "Hello ";    
    
        [DataMember]    
        public bool BoolValue    
        {    
            get { return boolValue; }    
            set { boolValue = value; }    
        }    
    
        [DataMember]    
        public string StringValue    
        {    
            get { return stringValue; }    
            set { stringValue = value; }    
        }    
    }    
}    

Service1.svc 

using System;    
using System.Collections.Generic;    
using System.Linq;    
using System.Runtime.Serialization;    
using System.ServiceModel;    
using System.ServiceModel.Web;    
using System.Text;    
    
namespace HelloWorldWCFService    
{    
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.    
    public class Service1 : IService1    
    {    
        public string GetData(int value)    
        {    
            return string.Format("You entered: {0}", value);    
        }    
    
        public CompositeType GetDataUsingDataContract(CompositeType composite)    
        {    
            if (composite == null)    
            {    
                throw new ArgumentNullException("composite");    
            }    
            if (composite.BoolValue)    
            {    
                composite.StringValue += "Suffix";    
            }    
            return composite;    
        }    
    }    
} 

Differences between Web Services and WCF Table

S.NumberFunctionsWCF
1It is available in the namespace "System.Web. Services.WebService Class"It is available in the namespace "System.ServiceModel"
2It is supported hosting only IISIt is supported hosting like IIS, Self Hosting (Console hosting), Windows Activation Services, Windows Services
3It is used for the XML Serializer onlyIt is used to DataContractSerializer only
4It is supported one-way communication and Request-ResponseIt is supported one-way, two-way (Duplex) communication and Request- Response
5It is supported binding like XML 1.0, Message Transmission Optimization Mechanism (MTOM), CustomIt is supported binding like XML 1.0, Message Transmission Optimization Mechanism (MTOM), Binary and Custom
6It is supported transport protocol like HTTP, TCP and customIt is the supported transport protocol like HTTP, TCP, Named Pipes, MSMQ, P2P and custom
7It is supported protocol securityIt is the supported protocol security, transaction and reliable message
Conclusion

This article will help to understand the differences between Web Services and WCF in .NET.
Windows Communication Foundation Web Service SOAP Web Protocols Protocol (object-oriented programming)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Toying With Kotlin’s Context Receivers
  • Best Practices for Resource Management in PrestoDB
  • How to Utilize Python Machine Learning Models
  • Flutter vs React Native. How to Cover All Mobile Platforms in 2022 With No Hassle

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo