WCF Introduction

WCF makes it possible to have a unified API irrespective of diverse transport mechanisms

Fundamental Concepts of WCF

  • Message
  • Endpoint: (WCF's ABC) places where messages are sent or received (or both), and they define all of the information required for the message exchange.
    • Address: is the URL of the Service. It consists of:
    • Transport
    • Machine Address
    • Service Path
    • Binding: Uses to generate the underlying wire representation of the endpoint
    • Transport(at least 1)
    • Encoding(at least 1)
    • Protocol(0 or more)
    • Contract: mechanisms by which a service's capabilities and requirements are specified for its consumers
  • Hosting Options:
    • Self-hosting
    • IIS hosting
    • WAS hosting
  • Metadata
  • WCF Client
  • Channel: medium through which a client communicates with a service
  • SOAP(Simple Object Access Protocol)
  • WSDL(Web Services Description Language): is a language that provides the ability for a web service to be able to give a description of the methods available through the web service.
  • WS-* is Web Service Standard

Advantages of WCF

  • Interoperable

Architecture

WCF Architecture Diagram

Contracts

Contains information similar to that of a real-world contract that specifies the operation of a service and the kind of accessible information it will make

Types of Contracts

  • Service contract Provides information to the client as well as to the outer world about the offerings of the endpoint, and the protocols to be used in the communication process.
  • Data contract defines the data exchanged by a service. Both the client and the service has to be in agreement with the data contract.
  • Message contract does the customization of the type formatting of the SOAP message parameters
  • Policy and Binding contract

Service Runtime

Specifies the various service behaviors that occur during runtime

  • Throttling Behavior
  • Error Behavior
  • Metadata Behavior
  • Instance Behavior
  • Transaction Behavior
  • Dispatch Behavior
  • Concurrency Behavior
  • Parameter Filtering

Messaging

mainly deals with the message content to be communicated between two endpoints

  • Transport Channels: HTTP, TCP, Peer-to-Peer, Named Pipes, and MSMQ
  • Protocol Channels: Also known as layered channels, implement wire-level protocols by modifying messages

Activation and Hosting

  • IIS (Internet Information Service)
  • WAS (Windows Activation Service)
  • Self Hosting
  • Windows Services

WCF Client

  • Client can either use svcutil.exe to generate Proxy for the Service using the wsdl
  • Use Channel Factory which will need access to Contract Interface Dlls to be shared with the client.

WCF Hosting

IIS

  • IIS Express
  • ASP.Net Development Server

Managed Application

  • Console App
  • Windows App
  • Windows Service

Benefits of Hosting WCF using TCP

  • It supports connection-based, stream-oriented delivery services with end-to-end error detection and correction
  • It is the fastest WCF binding for scenarios that involve communication between different machines
  • It supports duplex communication and so it can be used to implement duplex contracts
  • It has reliable data delivery capability (applies between two TCP/IP nodes, and is not the same thing as WS-ReliableMessaging, which applies between endpoints)

WCF 3 tier Architecture

Service interface layer

  • service contracts
  • data contracts
  • fault contracts

Business Logic Layer

  • actual business logic
  • preconditions of each operation

Data Access Layer

  • tasks needed to access the underlying databases
  • specific data adapter to query and update the databases
  • handle connections to databases
  • Manage Transections
  • Concurrency

Behaviors in WCF

  • IServiceBehavior Attaches directly to the Service
    • Validate
    • AddBindingParameters
    • ApplyDispatchBehavior
  • IOperationBehavior Has to be attached to an Operation. Not Automatic
    • Validate
    • ApplyDispatchBehavior
    • ApplyClientBehavior
    • AddBindingParameters
  • IParameterInspector
    • BeforeCall
    • AfterCall
  • BehaviorExtensionElement Is a Configuration Element
    • CreateBehavior
    • BehaviorType

Discoverability

  • Uses WS-Discovery protocol
  • Scope
  • UDP
  • Announcement
  • DynamicEndpoint

Ad-Hoc Discoverability

  • Based on UDP

Binding

  • What is Reliable Session?