http://www.c-sharpcorner.com/UploadFile/db2972/wcf-introduction-and-contracts-day-1/
Introduction
This article demonstrates how to create a WCF service application. This article also covers basic information of all the contracts and a code demonstration.
What is WCF?
WCF is a combined feature of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication. It is a part of .Net 3.0.

Difference between WCF and Web service
In a web service we need to add the [WebService] attribute to the class.
In WCF we need to add the [ServiceContract] attribute to the class.
Add the [WebMethod] attribute to the method in a web service.
Add the [OperationContract] attribute to the method in WCF.
For serialization in a web service use the System.Xml.serialization namespace.
WCF uses the System.Runtime.Serialization namespace for serialization.
We can host a web service in IIS.
We can host WCF in IIS, WAS (Windows Activation Service), self-hosting and a Windows Service .
Let's see how to create a WCF service application step-by-step.
Step 1
Start Menu >> All Programs >> Microsoft Visual Studio 2010 >> Microsoft Visual Studio 2010
In that "File" >> "New" >> "Project..."

Step 2
Select WCF from Installed Templates
Select .NET Framework 4 from dropdownlist
Select WCF Service Application
Give desired name and select the location
Click on OK button
Step 3
Now your Windows Communication Foundation service application is ready as a default service. You will see in Solution Explorer Service1.svc and IService1.cs
Open the IService1.cs file, as in:

In this file you willl find a ServiceContract, OperationContract and DataContract.
Service Contract
Service contract is an attribute applied to an interface i.e. IService1. It describes which operations the client can perform on the services.

Operation Contract
Operation Contract is an attribute applied to methods in interfaces i.e. IService1. It is used to define a method in an interface.

Data Contract
DataContract defines which data types are passed to and from the service. It is used to define a class and the DataMember attribute is used to define the properties.

WCF Contracts map directly to a corresponding web services standard:
ServiceContracts map to WSDL
DataContracts map to XSD
MessageContracts map to SOAP
Comments
Post a Comment