520 likes | 866 Views
Windows Communication Foundation (WCF). Dhananjay Kumar MVP-Connected System. WCF. Agenda What is WCF ? Why WCF? Address , Binding, Contract End Points Hosting Message Patterns Programming Model Basic Task Cycle. From Objects to Services. Object-Oriented. Polymorphism
E N D
Windows Communication Foundation(WCF) Dhananjay Kumar MVP-Connected System
WCF • Agenda • What is WCF ? • Why WCF? • Address , Binding, Contract • End Points • Hosting • Message Patterns • Programming Model • Basic Task Cycle
From Objects to Services Object-Oriented Polymorphism Encapsulation Subclassing 1980s Component-Based Interface-based Dynamic Loading Runtime Metadata 1990s Service-Oriented Message-based Schema+Contract Binding via Policy 2000s
The Four Tenets of Service-Orientation Boundaries are Explicit Developers opt-in to consuming, exposing, and defining public-facing service façade. Services and consumers are independently versioned, deployed, operated, and secured. Autonomous Evolution Data never includes behavior; Objects with data and behavior are a local phenomenon. Share schema & contract, not class Compatibility based on policy Capabilities and requirements represented by a unique public name; Used to establish service suitability.
Benefits of Service Orientation Facilitates implementation/platform interop Independent deployment, versioning, mgmt Promotes technology reuse
The Challenge Radically Simplifying Distributed Application Development Development of connected systemsremains costly and frustrating • Different programming models for different tasks • Need for security and reliable messaging • Interoperability with applications on other platforms • Productive service-oriented programming model needed
WCF Unified framework for rapidly building service-oriented applications
WCF • What is WCF ? • Service Oriented programming model to develop connected applications. • SDK to develop and deploy services on windows. • Unifies the existing suite of .Net distributed technologies into a single programming model. Microsoft Innovation & Practice Team, MSCoE
WCF Design Goals • Unifies today’s distributed technology stacks • Compose able functionality Unification “The unified programming model for rapidly building service-oriented applications on the Windows platform” Productive Service-Oriented Programming • Service-oriented programming model • Supports 4 tenets of service-orientation • WS-* interoperability with applications running on other platforms • Interoperability with today’s distributed stacks Interoperability & Integration
Message Services and Clients Client Service Message
Endpoint Endpoint Endpoint Endpoints Client Service Message
End Points Microsoft Innovation & Practice Team, MSCoE
C C C B B B A A A Address, Binding, Contract Client Service Message Address Binding Contract (Where) (How) (What)
Transport Encoder Protocol(s) Transport Encoder Protocol(s) WCF Architecture: Messaging Runtime Service Contract andBehaviors Client Dispatcher Binding Address
Address Every service is associated with a unique address. Microsoft Innovation & Practice Team, MSCoE
Address • WCF supports following Transport Microsoft Innovation & Practice Team, MSCoE
Binding • Describes how a service communicates • Specifies set of binding elements • Transport; http, tcp, np, msmq • Encoding format; text, binary, MTOM, ... • Security requirements • Reliable session requirements • Transaction requirements • Set of predefined standard bindings • Can be customized • Custom binding Microsoft Innovation & Practice Team, MSCoE
Bindings & Binding Elements Binding HTTP Text Security Reliability TX Transport Protocol Encoders TCP HTTP Security Reliability Text Binary MSMQ IPC TX .NET Custom Custom Custom
Binding Microsoft Innovation & Practice Team, MSCoE
ASMX/WSE3 WCF MSMQ WCF WCF WCF Other Platform WCF ASMX/WSE3 WCF MSMQ WCF Other Platform WCF Choosing Bindings Any Protocol AnyBinding AnyBinding WS-* Protocols Http/WSBinding WS-* Protocols Http/WSBinding WS-* Protocols Http/WSBinding WS-* Protocols Http/WSBinding MSMQ Protocol MSMQBinding MSMQ Protocol MSMQBinding
Configuring Bindings <endpoint address="Calculator" bindingSectionName="basicProfileBinding" bindingConfiguration="Binding1" contractType="ICalculator" /> <bindings> <basicProfileBinding> <binding configurationName="Binding1" hostnameComparisonMode="StrongWildcard" transferTimeout="00:10:00" maxMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" </binding></basicProfileBinding></bindings>
Contracts • WCF services exposes contract. • This is a platform neutral and standard • This says , what a service will do. • Defines , what a Service communicate Microsoft Innovation & Practice Team, MSCoE
Types of Contracts Microsoft Innovation & Practice Team, MSCoE
Service Contracts • Describes what a service does • Maps CLR types to WSDL • [ServiceContract] defines the service contract • [OperationContract] specifies operations • One-way, request-reply, duplex MEPs, Sessions, Faults
Data Contract • Defines data structures • Maps CLR types to XML Schema • [DataContract] specifies types • [DataMember] specifies members • Can be applied to private fields!
Message Contract [MessageContract] public class ComplexProblem { [MessageHeader] public string operation; [MessageBody]public ComplexNumber n1; [MessageBody]public ComplexNumber n2; [MessageBody]public ComplexNumber solution; // Constructors… }
End Points • Each service must expose at least one business endpoint. • Each End point has exactly one contract. • All endpoint on service have a unique addresses. • A single service can expose multiple end points. • Multiple exposed endpoint for single service can use same or different Bindings. • Multiple exposed endpoint for single service can use same or different Contracts. • There is no relationship in between various endpoint service provides.
Defining Endpoints <?xml version="1.0" encoding="utf-8" ?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.serviceModel> <services> <service serviceType="CalculatorService"> <endpoint address="Calculator" bindingSectionName="basicProfileBinding" contractType="ICalculator" /> </service> </services> </system.serviceModel> </configuration>
Hosting • WCF services can not exist in void. • It must be hosted. • WCF services are hosted in windows process called host process. • A single host process can host multiple service. • A same service can be hosted in multiple host process. Microsoft Innovation & Practice Team, MSCoE
Steps in creating WCF Service Defining .Net service interface to serve as the Service contract Implement Service Contract in .Net class as Service type and configure its behavior Configure the End Point where service will expose , by specifying A,B,C Host Service type in application using WCF hosting infrastructure At client side ,By using description of target End Point create PROXY. And write code against this Proxy.
WCF Thank You