WCF Basics

WCF:
*
  • Common platform for communication
  • WCF provides: service instance management, asynchronous calls, reliability, transaction management, disconnected queued calls, security
  • Assembly name: System.ServiceModel.dll
  • WCF is extendible to enrich basic offerings.
  • Exposes collection of Endpoint

Hosting Environment
  • IIS Hosting
    • HTTP Only
  • Windows Service
  • IIS7 (Windows Activation Service)
    • Feature from Windows Vista
    • Provides improved manageability
  • Windows presentation foundation
  • Self Hosting
    • ServiceHost class

Endpoint Address
  • WCF supports: HTTP, TCP, Peer Network, Named pipes, MSMQ
  • Format: [transport] :// [domain] [:port] / [URI]
Example:
http://localhost:8001
http://localhost:8001/MyService
net.tcp://localhost:8002/MyService
net.pipe://localhost/MyPipe
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService

Contract:
  • Collection of Operations
  • Exchange of Message
  • Type: Service, Data, Fault, Message
  • Communication Type: One way, Duplex, Request/ Reply

Type:
Service Contract: Describe which operations the client can perform on the service.
Data Contract:
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 you can easily define explicit opt-in data contracts for custom types.
Fault Contract:
Define which errors are raised by the service, and how the service handles and propagates errors to its clients.
Message Contract:
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 you have to comply with. As a WCF developer, you should use message contracts only rarely.


Versioning:
  • WCF supports lax versioning
  • Need to remember
    • The old clients were developed with the assumption that the schema will not change. They may fail to process messages that they were never designed for.
    • The old clients may perform actual schema validation against the old schema before even attempting to process the messages
Binding:

  • How Communicating with the Endpoint
  • Defines transport protocol, message encoding, communication pattern, reliability, security, transaction propagation and interoperability.
Binding Standard:

Basic binding : Offered by the BasicHttpBinding class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.
TCP binding: Offered by the NetTcpBinding class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF. Peer network binding: Offered by the NetPeerTcpBinding class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.
IPC binding: Offered by the NetNamedPipeBinding class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.
Web Service (WS) binding: Offered by the WSHttpBinding class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.
Federated WS binding: Offered by the WSFederationHttpBinding class, this is a specialization of the WS binding, offering support for federated security.
Duplex WS binding: Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client
MSMQ binding: Offered by the NetMsmqBinding class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.
MSMQ integration binding: Offered by the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

Comments

Popular Posts