Tuesday, 31 July 2012

WCF - ABC of WCF

What is Address in WCF? What are the various transport schema available in WCF?
ü  Address is a way of letting client know that where a service is located.
ü   In WCF, every service is associated with a unique address.
ü   This contains the location of the service and transport schemas. 
ü  Address format of WCF transport schema always follow 
Ø  [Transport]://[machine or domain][:optional port]. 
ü  WCF supports following transport schemas 
ü  HTTP 
ü  TCP 
ü  Peer network 
ü  IPC (Inter-Process Communication over named pipes) 
ü  MSMQ 

HTTP Address Format 
http://localhost:8888
the way to read the above URL is "Using HTTP, go to the machine called localhost, where on port 8888 someone is waiting"
When the port number is not specified, the default port is 80. 
TCP Address Format 
net.tcp://localhost:8888/MyService
when a port number is not specified, the default port is 808:
net.tcp://localhost/MyService
NOTE: Two HTTP and TCP addresses from the same host can share a port, even on the same machine. 

IPC Address Format 
net. Pipe://localhost/MyPipe
We can only open a named pipe once per machine, and therefore it is not possible for two named pipe addresses to share a pipe name on the same machine. 


MSMQ Address Format 
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService


What is Binding in WCF? What are characteristics of Binding in WCF?
ü  Binding describes how client will communicate with service.
ü  There are different protocols available for the WCF to communicate to the Client.
ü  You can mention the protocol type based on your requirements.
ü  A binding has several characteristics, including the following:
·         Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.
·         Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).
·         Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capability
ü  The following table gives some list of protocols supported by WCF binding.

Binding
Description
BasicHttpBinding
Basic Web service communication. No security by default
WSHttpBinding
Web services with WS-* support. Supports transactions
WSDualHttpBinding
Web services with duplex contract and transaction support
WSFederationHttpBinding
Web services with federated security. Supports transactions
MsmqIntegrationBinding
Communication directly with MSMQ applications. Supports transactions
NetMsmqBinding
Communication between WCF applications by using queuing. Supports transactions
NetNamedPipeBinding
Communication between WCF applications on same computer. Supports duplex contracts and transactions
NetPeerTcpBinding
Communication between computers across peer-to-peer services. Supports duplex contracts
NetTcpBinding
Communication between WCF applications across computers. Supports duplex contracts and transactions

What are contracts in WCF? 
ü  Collection of operation that specifies what the endpoint will communicate with outside world.
ü  Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client.
ü  Each operation is a simple exchange pattern such as one-way, duplex and request/reply.

    What are various types contracts in WCF?
In WCF, all services expose contracts. The contract is a platform-neutral and standard way of describing what the service does.

WCF defines four types of contracts.
  • Service contracts: Describe which operations the client can perform on the service.
  • Data contracts: Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.
  •  Fault contracts: Define which errors are raised by the service, and how the service handles and propagates errors to its clients.
  • Message contracts: Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.





No comments:

Post a Comment