WCF Introduction
WCF Introduction
Foundation
(WCF)
Introduction
• WCF is a unified programming model for
building service oriented application.
• It is used to build
– Secure
– Reliable
• applications that integrate across platforms
and interoperate with existing applications.
Features of WCF
• Service orientation
• Loosely coupled
• Interoperability
• Multiple message patterns
– Request-reply, one-way, duplex
• Publishing service metadata
– WSDL, XSD, WS-Policy
• Data Contract
– Classes
Features of WCF
• Security
– SSL, WS-SecureConversation
• Multiple Transports and Encodings
– HTTP, TCP, named Pipe
– Text, binary encoding (MTOM-Message Transmission
Optimization Mechanism)
• Reliable and Queued Messages
– WS-Reliable messaging and MSMQ
• Durable Messages
Features of WCF
• Transactions
– WS-AtomicTransaction, API, MS Distributed
Transaction Coordinator
• AJAX and REST support
– XML, JSON
• Extensibility
• Multiple service hosting options
– IIS, app-hosting
The Challenge
Radically Simplifying Distributed Application Development
ASMX
MSMQ WSE
COM+
(Enterprise .NET Remoting
Services)
UNDERSTANDING WCF PRINCIPLES
Services and Clients
Endpoints
Endpoint
Endpoint Endpoint
Address, Binding, Contract
Service
B
WCF Architecture
Contract
and
Behaviors
Protocol(s) Protocol(s)
Encoder
Binding
Encoder
Transport Transport
Address
CONTRACTS
Three Types of Contracts
Client Service
Request-Reply
Duplex (Dual)
• One Way:
– Datagram-style delivery
• Request-Reply
– Immediate Reply on same logical thread
• Duplex
– Reply “later” and on backchannel (callback-style)
What does your service do?
SERVICE CONTRACTS
Service Contract
using System.ServiceModel;
[ServiceContract]
public interface ICalculate
{
[OperationContract]
double Add( double a, double b);
[OperationContract]
double Subtract( double a, double b);
}
What object data needs to flow back and forth?
DATA CONTRACTS
Data Contract
[DataContract]
public class ComplexNumber
{
[DataMember]
public double Real = 0.0D;
[DataMember]
public double Imaginary = 0.0D;
MESSAGE CONTRACTS
Message Contract
[MessageContract]
public class ComplexProblem
{
[MessageHeader]
public string operation;
[MessageBody]
public ComplexNumber n1;
[MessageBody]
public ComplexNumber n2;
[MessageBody]
public ComplexNumber solution;
// Constructors…
}
How?
BINDINGS
Bindings & Binding Elements
Binding
HTTP Text Security Reliability TX
Custom
Custom Custom
Standard Bindings
Binding Interop Security Session TX Duplex