Sunday 31 May 2015

What are WCF bindings and How to choose WCF binding ?

Here In this post I expalined all bindings in WCF. The cinarios where which binding is most suitable and what they supports.


Bindings and Explaination:-

Sl.No
Binding Name
Binding class and Description
1
Basic binding
We use BasicHttpBinding class to implement this binding. It is designed to expose a WCF service as an ASMX web service (asp.net web service), so that old clients (which are still using ASMX web service) can consume new service. By default, it uses Http protocol for transport and encodes the message in UTF - 8 text for-mat. You can also use Https with this binding.
2
Web binding
We use WebHttpBinding class to implements this binding. It is designed to expose WCF services as Http requests by using HTTP-GET, HTTP-POST. It is used with REST based services which may give output as an XML or JSON format. This is very much used with social networks for implementing a syndication feed.
3
Web Service (WS) binding
We use WSHttpBinding class to implement this binding. It is similar to Basic binding and uses Http or Https protocols for transport. But this is designed to offer various WS - * specifications such as WS – Reliable Messaging, WS - Transactions, WS - Security and so on which are not supported by Basic binding.
 wsHttpBinding = basicHttpBinding + WS-* specification
4
WS Dual binding

We use WsDualHttpBinding class to implement this binding. It is similar to wsHttpBinding except it sup-ports bi-directional communication means both clients and services can send and receive messages.
5
TCP binding
We use NetTcpBinding class to implement this binding. It uses TCP protocol to communicate between two machines with in intranet (means same network). It encodes the message in binary format. This is faster and more reliable binding as compared to the Http protocol bindings. It is only used when communication is WCF  to WCF means both client and service should have WCF.
6
IPC binding

We use NetNamedPipeBinding class to implement this binding. It uses named pipe to Communicate between two services on the same machine. This is the most secure and fastest binding among all the bindings.
7
MSMQ binding

We use NetMsmqBinding class to implement this binding. It uses MSMQ for transport and offers sup-port to disconnected message queued. It provides solutions for disconnected scenarios in which service processes the message at a different time than the client send the messages.
8
Federated WS binding
We use WSFederationHttpBinding class to implement this binding. It is a specialized form of WS binding and provides support to federated security.
9
Peer Network binding

We use NetPeerTcpBinding class to implement this binding. It uses TCP protocol but uses peer net-working as transport. In this networking each machine (node) acts as a client and a server to the other nodes. This is used in the file sharing systems like torrent.
10
MSMQ Integration binding
We use MsmqIntegrationBinding class to implement this binding. This binding offers support to communicate with existing systems that communicate via MSMQ.


How to choose binding and which binding is most suitable in wchich cinarios:-




What they supports:-

Sl.No
Binding Name
Message Encoding
Protocol
Security
Transaction
Bi-directional
1
Basic binding
Text
Http, Https
None
-----
------
2
Web Service (WS) binding
Text
Http, Https
Message
Yes
------
3
WS Dual binding
Text
Http, Https
Message
Yes
Yes
4
TCP binding
Binary
TCP
Transport
Yes
Yes
5
IPC binding

Binary
Named pipe
Transport
Yes
Yes
6
MSMQ binding

Binary
MSMQ
Message
Yes
No
7
Federated WS binding
Text
Http, Https
Transport
Yes
No
8
Peer Network binding

Binary
Peer to Peer
Transport
No
Yes
9
MSMQ Integration binding
Not Supported
MSMQ
Transport
Yes
-----



In the above post I explained WCF bindings. Ihope its very useful to you. So please comments your feedback, question regarding this post.

Thursday 28 May 2015

Difference between WCF and asp.NET Web service

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.


Difference between WCF and Web service

Sl. No.
Features
WCF Service
ASP.NET Web Service
1
File Format /Extension
WCF web service uses .svc as a file extension.
ASP.net web services uses .asmx as a file extension.
2
Hosting
WCF service is flexible because it can be hosted in IIS, Windows Activation Services(WAS), Managed Windows Services and It also supports Self-Hosting.
It can be hosted only IIS
3
Protocol
Supports various protocols like HTTP, HTTPS, TCP, Named Pipes and MSMQ.
Supports only HTTP, HTTPS protocols.
4
Security
Supports security, reliable messaging, transaction and AJAX and REST supports.
Support security but is less secure as compared to WCF.
5
Communication
Supports One-Way, Request-Response and Duplex service operations.
Supports One-Way and Request-Response service operations.
6
Exception
Handling
Unhandled Exceptions does not return to the client as SOAP faults. WCF supports better exception handling by using FaultContract.
Unhandled Exceptions returns to the client as SOAP faults.
7
Performance
WCF are faster than Web Services.
Web Services are slower than WCF
8
Data Serialization
Supports DataContract serializer by using System.Runtime.Serialization.
Supports XML serializer by using System.Xml.Serialization.
9
Attribute
ServiceContract and OperationContract attributes are used for defining WCF service.
WebService and WebMethod attributes are used for defining web service.
10
Encoding      
Supports XML, MTOM, Binary message encoding.
Supports XML and MTOM (Message Transmission Optimization Mechanism) message encoding.
11
Model
[OperationContract] attribute represents the method exposed to client
[WebMethod] attribute represents the method exposed to client
12
Limitations  
The DataContractSerializer translate the Hash table into the XML.
Public/Private properties/fields can be serialized.
Hash Table cannot be serialized.
Only public properties/fields can be serialized




In the above post I Explained the almost differences between WCF and asp.net Web Service. I hope its useful to you. Please comments your feedback and questions.