RSS
Facebook
Twitter

Thursday 3 January 2013

WCF Basic Concept




                                                                                Concepts
1)      A WCF service allows communication through an Endpoint.
2)      The endpoint is the only point of communication of the WCF service that enables message exchange with the client as shown in Figure.


3)      And this Endpoint needs to set the ABC attributes of the WCF service as shown in Figure


4)      Thus in the WCF world, ABC is an abbreviation of AddressBinding and Contract attributes of an Endpoint.
Let us quickly run through an example of an endpoint setting in the web.config file at the service side. <! -- Endpoint settings in WCF service -->
<
endpoint address="http://192.168.0.10/RSMAPPService/AsgTechCall.svc/AsgTechCall.svc 
binding="basicHttpBinding" contract="EmployeeWCFService.ServiceContract.IEmployee" />

5)       Where, address is the network address of the service, binding specifies transport protocol (HTTP, TCP, etc.) selected for the service and contract is the interface the service implements. 
6)       What is the Binding?
·         The Binding is an attribute of an endpoint and it lets you configure transport protocol, encoding and security requirements as shown in Figure.


7)       Type of Binding :

·         WCF offers a single development framework for all scenarios where distributed solutions were implemented using different technologies such as ASMX web services, .Net Remoting, COM+, etc.
·         WCF achieves this by configuring binding attributes of an endpoint. 
·         WCF lets you choose HTTP or TCP transport protocol, encoding, etc. just by tweaking the value of binding attribute for an endpoint. 
·         To cater to different transport protocols, WCF lets you select HTTP, TCP and MSMQ (Microsoft Message Queuing) binding types.

MSMQ: - Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues. 

·         basicHttpBinding :
This type of binding exists in new .Net world only to support backward compatibility with ASMX based clients (WS-Basic Profile 1.1).
·          Basic http binding sends SOAP 1.1 messages and is used when there is a requirement for the WCF services to communicate with non WCF based systems. Thus, providing an endpoint with basicHttpBinding makes interoperating with other basic implementations of web services a great choice.

·         How to setup the basicHttpBinding?
<endpoint 
address="http://localhost:8731/EmployeeWCFService.ServiceImplementation.Manager/"binding="basicHttpBindingbindingConfiguration="basicBinding"contract=" EmployeeWCFService.ServiceContract.IEmployee">
         
·         wsHttpBinding :
This binding sends SOAP 1.2 messages and implements WS* specifications to support enterprise requirements of security, reliability, ordered delivery and transaction management. 
           
·         netTcpBinding :
This binding sends SOAP 1.2 messages, provides binary encoding and optimized communication between WCF services and WCF clients on Windows network. This binding is the fastest binding amongst all WCF binding options between different nodes in the TCP network.

Unlike http bindings, the TCP binding does not offer interoperability but is highly optimized for .Net 3.0 and above clients.

In .Net version 3.0 and above, providing an endpoint with netTcpBinding is an easy option to development of distributed systems and can replace COM+ and .Net Remoting model.
           
·         netNamedPipeBinding:
This binding is used to provide secure and reliable Named Pipe based communication between WCF services and WCF client on the same machine.

It is the ideal choice for communication between processes on the same machine.

·         Thumb rules in choosing endpoint' binding :
a)      If you require your service to be consumed by clients compatible with SOAP 1.1, use basicHttpBinding for interoperability.
b)     If you require your service to be consumed within the corporate network, use netTCPBinding for performance.
c)      If you require your service to be consumed over the internet and the client is a WCF compatible, use wsHttpBinding to reap full benefits of WS* specifications
d)     If you require your service to be accessible only in the same machine, use netNamedPipeBinding.
e)      If you require your service to be queue messages, use netMsmqBinding.
f)       If you require your service to act as server as well as client in a peer to peer environment, utilize netPeerTcpBinding setting.

·         Binding configuration summary:

Binding
Security 
Default Configurable
Transport Protocol
Encoding 
Default Other
Host
basicHttpBinding
None, 
Transport, Message, Mixed
HTTP
Text/XML, MTOM
IIS, WAS
wsHttpBinding
Message, Transport, Mixed
HTTP
Text/XML, MTOM
IIS, WAS
netTcpBinding
Transport, Message, Mixed
TCP
Binary
WAS
netNamedPipeBinding
Transport,None
Named Pipe
Binary
WAS
netMsmqBinding
Message, Transport, None
TCP
Binary
WAS
netPeerTcpBinding
Transport
P2P
Binary
-










·         FAQ about an Endpoint:           
Can I have multiple endpoints for a WCF service?
Answer: Yes

Can I have multiple endpoints of the same binding type e.g. multiple endpoints of basicHttpBinding?
Answer: Yes

Can I have multiple endpoints of different binding types to serve different types of clients e.g. an endpoint with basicHttpBinding, an endpoint with wsHttpBinding and an endpoint with netTcpBinding?
Answer: Yes

            Summary:
                       
As you have seen, Windows Communication Foundation provides a framework to configure the transport, security and encoding needs to cater various communication requirements. The WCF framework keeps the development API same irrespective of the way it is going to be consumed by the clients. And, the endpoint is provided to meet the communication requirements, and you can have one or many of them to cater to different clients and communication requirements. This eliminates the need to learn and implement diverse set of communication models to support HTTP or TCP communication infrastructures. 

0 comments:

Post a Comment