articles

Home / DeveloperSection / Articles / Addresses, Binding and Contracts (ABC) concept of WCF

Addresses, Binding and Contracts (ABC) concept of WCF

Addresses, Binding and Contracts (ABC) concept of WCF

priyanka kushwaha7156 13-Mar-2015

This article explains the use of Addresses (A), binding (B) and contracts (C) of WCF.

Introduction:

WCF provides a common method for communication in support of SOA (service-oriented architecture). Now, developers can use WCF instead of multiple technologies used earlier. WCF is a new communication subsystem to enable application, in one machine or across multiple machines connected through a network, to communicate.  These WCF applications can be developed in any language, which can target the .Net runtime.

EndPoint:

WCF service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world. All the WCF communications are taking place through endpoint

The <endpoint> element contains the following attributes:

ABC (Address, Binding, Contract) of WCF:

A: Address (where)

Address: WCF services must have an address. The address specifies the location of the service which will be exposed to clients that will use it to communicate with the service. The address’s protocol that WCF can provide: HTTP, TCP, NamedPipe, peer2peer, MSMQ.

B: Binding (How)

Binding: WCF binding is a set of binding elements and each element specify, how the service and client will communicate with each other. Each binding must have at least one transport element and one message encoding element.

Types of binding

  • Basic binding
  • Web binding
  • Web service binding(WS)
  • WS dual binding
  • TCP binding
  • IPC binding
  • Federated WS binding
  • MSMQ binding
  • Peer Network binding
  • MSMQ Integration binding 

Basic binding:

This binding is provided by the BasicHttpBinding class.

  • This is interoperable binding.
  • This is commonly used as a replacement for earlier web service on ASMX.
  • It supports Http & Https protocols.
  • It supports Message transmission Optimization Mechanism (MTOM) encoding.
  • It supports text encoding. 

Web binding:

This binding is provided by the WebHttpBinding class.

  • This is a secure binding.
  • This is an interoperable binding.
  • It supports Http/Https protocol.
  • It does not use the SOAP message format. 

Web service (WS) binding:

This binding is provided by the WSHttpBinding class.

  • This is a secure binding.
  • This is interoperable binding.
  • This uses SOAP over Http.
  • This support reliability over the internet.
  • This support transaction over the internet.
  • This supports Http/Https protocol.
  • This supports text and MTOM encoding.
  • This is default binding providing by WCF. 

WS Dual binding:

This binding is provided by the WsDualHttpBinding class.

  • This support all the feature of WsHttpBinding.
  • This is mainly used for Duplex Service Contracts.
  • This supports bidirectional communication. 

TCP binding:

This binding is provided by the NetTcpBinding class. NetTcpBinding is primarily used for cross-machine communication on the Intranet and supports a variety of features, including reliability, transactions, and security and is optimized for WCF-to-WCF communication only .net clients can communicate to .net services using this binding. This is an ideal replacement for socket-based communication.

IPC binding: 

This binding is provided by the NetNamedPiped class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept the call from outside the machine and it supports a variety of features similar to the TCP binding. It can be used efficiently for cross-product communication.

Federated WS binding:

This binding is providing by the WSFederationHttpBinding class.

The WSFederationHttpBinding binding is a specialization of the WS binding, offering support for federated security.

Peer Network binding:

This binding is provided by the NetPeerTcpBinding Class.

The NetPeerTcpBinding is used for peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast message to it.

MSMQ binding:

This binding is provided by the NetMsmqBinding class. NetMsmqbinding uses MSMQ for transport and is designed to offer support for disconnected queued calls.

MSMQ integration binding:

This binding is provided by the MsmqIntegrationBinding class.

MsmqIntegrationBinding converts the WCF message to and from Msmq messages and is designed to interoperate with legacy MSMQ clients. 

C: contract (What)

The contract is an agreement between the client and the server about the structure and content of the message being exchanged.

The data contract is about the structure of the message, whereas the message contract is about the content of the message being exchanged.

Types of Contract:

  • Service Contract
  • Operation Contract
  • Data Contract
  • Message Contract
  • Fault contract

Service contracts:

Describe which operations the client can perform on the service.

Operation contract:

An operating contract is defined within a service contract.  It defines the parameters and return types of operation. An operation contract can also defines operation-level settings.

Data contract:

Define which data types are passed to and from the service. WCF defines an implicit contract for built-in types such as int and string, but you can easily define explicit Opt-in contracts for custom types.

Fault contract:

A fault contract defines errors raised by the services, and how the service handles and propagates errors on its clients. An operation contract can have zero or more fault contracts associated with it.

Message Contract:

Default SOAP message format is provided by the WCF runtime for communication between client and service. If it is not meeting your requirement then we can create our own message format.  This can be achieved by using Message Contract attribute.


Updated 24-Feb-2020

Leave Comment

Comments

Liked By