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; }
- }
- }
- }

Vikash TiwariPosted Sep 20, 2018, 4:04 AM
Good article Sir
Vignesh ManiPosted Apr 26, 2016, 4:41 PM
Good one
Asfend YarPosted Mar 6, 2016, 2:11 PM
what is the solution if database is involved in web service
Asfend YarPosted Mar 6, 2016, 2:11 PM
good
Sr KarthigaPosted Mar 2, 2016, 10:45 PM
good one
Sr KarthigaPosted Mar 2, 2016, 10:45 PM
nice explanation
Santhakumar MunuswamyPosted Dec 19, 2015, 12:08 AM
Thanks Manoj Kalla
Manoj KallaPosted Dec 19, 2015, 12:05 AM
Very good article. Thank you for sharing.
Santhakumar MunuswamyPosted Nov 28, 2015, 12:49 AM
Thanks Arul R
Santhakumar MunuswamyPosted Nov 28, 2015, 12:49 AM
Thanks Raja T
Santhakumar MunuswamyPosted Nov 28, 2015, 12:49 AM
Thanks Ajeet Mishra
Santhakumar MunuswamyPosted Nov 28, 2015, 12:49 AM
Thanks Lalit Raghav
Arul RPosted Oct 28, 2015, 5:49 AM
Nice share!!!
Raja TPosted Sep 14, 2015, 8:13 AM
Good one,Thanks for sharing
Ajeet MishraPosted Sep 14, 2015, 8:12 AM
nice
Lalit RaghavPosted Sep 8, 2015, 3:56 AM
Great Sir
Santhakumar MunuswamyPosted Aug 5, 2015, 2:49 PM
Thanks Neeraj Pokhriyal
Neeraj PokhriyalPosted Aug 5, 2015, 2:48 PM
good article
Santhakumar MunuswamyPosted Apr 30, 2015, 1:57 PM
Thanks Nitin Tyagi
NitinPosted Apr 26, 2015, 4:04 AM
good one