WCF tutorial – Learn WCF quickly
WCF stands for Windows Communication Foundation and used for developing distributed system.
WCF services can communicate with.Net applications and Non-Microsoft technology as well.
- (A) Address – Where to bind, which is also called as EndPoint
- (B) Binding – How to bind
- (C) Contract – What to bind
ASMX service sends and receives data over HTTP protocol; however, WCF is able to exchange messages over any transport protocol.
The contract in WCF:
There are multiple contracts available in WCF. Generally, a standard way to describe what exactly a service will do.
Service Contract – Defines the operation that a service will perform.
Data Contract – Defines the classes
Fault Contract – Defines the errors raised in service
Message Contract – Defines what data need to exchange
Protocol that WCF uses:
HTTP – eg http://localhost:80
TCP – net.tcp//localhost:90
MSMQ – net.msmpq://localhost:91
Hosting in WCF:
There are 3 types of hosting options available in WCF
System.ServiceModel is the namespace which is used to access WCF Service.
Types of Binding in WCF – Binding defines how an endpoint communicates to the world. It also defines the transport protocol i.e. HTTP, TCP
What is Data Contract Serialization?
What is Proxy and How to generate it?
Proxy is a class that exposes the service contract.
A proxy can be generated using Visual Studio by adding service reference; another way to generate proxy is by using Svcutil.exe command. Need to provide the service address and proxy file name (optional). Default proxy name is output.cs
Svcutil http://serviceurl/myservice.svc /out:MyProxy.cs
WCF client Configuration:
<endpoint name = “EndPoint1” address=”endpointurl” binding =”wsHttpBinding” contract =”IContract”/>
Operation Overloading in WCF Service:
By default operation, overloading is not allowed. But using Name property with operation contract can resolve this issue.
public interface IService1
string GetData(int value);
string GetData(string value);
Main components of WCF :
Isolation level in WCF:
Read Uncommitted – An uncommitted transaction can be read. This transaction can be rolled back later.
Read Committed – Will not read data of a transaction that has not been committed yet.
Repeatable Read – Locks placed on all data.
Serializable – Does not allow other transactions to insert or update data until the transaction is complete.
Please follow and like us: