Windows Communication Foundation WCF Dhananjay Kumar MVPConnected System

  • Slides: 36
Download presentation
Windows Communication Foundation (WCF) Dhananjay Kumar MVP-Connected System 1

Windows Communication Foundation (WCF) Dhananjay Kumar MVP-Connected System 1

WCF � Agenda �What is WCF ? �Why WCF? �Address , Binding, Contract �End

WCF � Agenda �What is WCF ? �Why WCF? �Address , Binding, Contract �End Points �Hosting �Message Patterns �Programming Model �Basic Task Cycle 2

From Objects to Services Object-Oriented 1980 s Polymorphism Encapsulation Subclassing Component-Based 1990 s Interface-based

From Objects to Services Object-Oriented 1980 s Polymorphism Encapsulation Subclassing Component-Based 1990 s Interface-based Dynamic Loading Runtime Metadata Service-Oriented 2000 s Message-based Schema+Contract Binding via Policy

The Four Tenets of Service-Orientation Boundaries are Explicit Developers opt-in to consuming, exposing, and

The Four Tenets of Service-Orientation Boundaries are Explicit Developers opt-in to consuming, exposing, and defining public-facing service façade. Autonomous Evolution Services and consumers are independently versioned, deployed, operated, and secured. Share schema & contract, not class Data never includes behavior; Objects with data and behavior are a local phenomenon. 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

Benefits of Service Orientation Facilitates implementation/platform interop Independent deployment, versioning, mgmt Promotes technology reuse

The Challenge Radically Simplifying Distributed Application Development of connected systems remains costly and frustrating

The Challenge Radically Simplifying Distributed Application Development of connected systems remains 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 Unified framework for rapidly building service-oriented applications

WCF � What is WCF ? �Service Oriented programming model to develop connected 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, MSCo. E 8

WCF Design Goals “The unified programming model for rapidly building serviceoriented applications on the

WCF Design Goals “The unified programming model for rapidly building serviceoriented applications on the Windows platform” Unification Productive Service-Oriented Programming Interoperability & Integration Unifies today’s distributed technology stacks Compose able functionality Service-oriented programming model Supports 4 tenets of service-orientation WS-* interoperability with applications running on other platforms Interoperability with today’s distributed stacks

Services and Clients Client Message Service

Services and Clients Client Message Service

Endpoints Client Service Endpoint Message Endpoint

Endpoints Client Service Endpoint Message Endpoint

End Points Contracts Address Binding End Point Microsoft Innovation & Practice Team, MSCo. E

End Points Contracts Address Binding End Point Microsoft Innovation & Practice Team, MSCo. E 12

Address, Binding, Contract Client Service C B A Message A B C Address Binding

Address, Binding, Contract Client Service C B A Message A B C Address Binding Contract (Where) (How) (What)

WCF Architecture: Messaging Runtime Client Service Dispatcher Protocol(s) Encoder Transport Contract and Behaviors Binding

WCF Architecture: Messaging Runtime Client Service Dispatcher Protocol(s) Encoder Transport Contract and Behaviors Binding Address

Address Every service is associated with a unique address. Location of the Service Transport

Address Every service is associated with a unique address. Location of the Service Transport protocol used in service Address of the Service Microsoft Innovation & Practice Team, MSCo. E 15

Address � WCF supports following Transport � HTTP TCP MSMQ IPC Peer network •

Address � WCF supports following Transport � HTTP TCP MSMQ IPC Peer network • http: //localhost: 8001/Dell • http: //localhost/Dell • net. tcp: //localhost: 800/Dell • net. tcp: //localhost/Dell • net. msmq/private/My. Service • Net. msmq/: //localhost/Dell • net. pipe: //localhost/My. Pipe • Net. pipe: //localhost. My. Service Microsoft Innovation & Practice Team, MSCo. E 16

Binding �Describes how a service communicates �Specifies set of binding elements �Transport; http, tcp,

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, MSCo. E 17

Bindings & Binding Elements Binding HTTP Transport Text Security Reliability TX Protocol Encoders TCP

Bindings & Binding Elements Binding HTTP Transport Text Security Reliability TX Protocol Encoders TCP HTTP Text Security Reliability MSMQ IPC Binary TX . NET Custom

Binding Name as of class Transport Encoding Inte rop erab le Basic. Http. Binding

Binding Name as of class Transport Encoding Inte rop erab le Basic. Http. Binding HTTP/HTTPS Text, MTOM Yes Net. Tcp. Binding TCP Binary No Net. Peer. Binding P 2 P Binary No Net. Named. Pipe. Binding IPC Binary No WSHttp. Binding HTTP/HTTPS Text, MTOM Yes WSFederation. Http. Binding HTTP/HTTPS Text, MTOM Yes WSDual. Http. Binding HTTP Text, MTOM Yes Net. Msmq. Binding MSMQ Binary No Msmq. Integration. Binding MSMQ Binary Yes Microsoft Innovation & Practice Team, MSCo. E 19

Choosing Bindings WCF Any Binding Http/WS Binding MSMQ WCF WS-* Protocols Http/WS Other Platform

Choosing Bindings WCF Any Binding Http/WS Binding MSMQ WCF WS-* Protocols Http/WS Other Platform WCF Any Binding WS-* Protocols Http/WS ASMX/WSE 3 WCF Any Protocol Binding Http/WS Binding WS-* Protocols MSMQ Protocol MSMQ Binding MSMQ Protocol WCF ASMX/WSE 3 WCF Other Platform WCF MSMQ

Configuring Bindings <endpoint address="Calculator" binding. Section. Name="basic. Profile. Binding" binding. Configuration="Binding 1" contract. Type="ICalculator"

Configuring Bindings <endpoint address="Calculator" binding. Section. Name="basic. Profile. Binding" binding. Configuration="Binding 1" contract. Type="ICalculator" /> <bindings> <basic. Profile. Binding> <binding configuration. Name="Binding 1" hostname. Comparison. Mode="Strong. Wildcard" transfer. Timeout="00: 10: 00" max. Message. Size="65536" message. Encoding="Text" text. Encoding="utf-8" </binding> </basic. Profile. Binding> </bindings>

Contracts �WCF services exposes contract. �This is a platform neutral and standard � �This

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, MSCo. E 22

Types of Contracts • Describes which operation client can perform on the Service services.

Types of Contracts • Describes which operation client can perform on the Service services. Contract Data Contract Fault Contract • Defines which Data Type are passed to and from the services. It provides built-in contract for implicit type. • Which error raise by service and how service propagates and handles error to its client. • Allow the service to interact directly with tche message. Message contract can be typed or un typed. This can be Message Contract used for interoperability. Microsoft Innovation & Practice Team, MSCo. E 23

Service Contracts �Describes what a service does �Maps CLR types to WSDL �[Service. Contract]

Service Contracts �Describes what a service does �Maps CLR types to WSDL �[Service. Contract] defines the service contract �[Operation. Contract] specifies operations �One-way, request-reply, duplex MEPs, Sessions, Faults

A Service Contract

A Service Contract

Data Contract �Defines data structures �Maps CLR types to XML Schema �[Data. Contract] specifies

Data Contract �Defines data structures �Maps CLR types to XML Schema �[Data. Contract] specifies types �[Data. Member] specifies members �Can be applied to private fields!

A Data Contract

A Data Contract

Message Contract [Message. Contract] public class Complex. Problem { [Message. Header] public string operation;

Message Contract [Message. Contract] public class Complex. Problem { [Message. Header] public string operation; [Message. Body] public Complex. Number n 1; [Message. Body] public Complex. Number n 2; [Message. Body] public Complex. Number solution; // Constructors… }

End Points �Each service must expose at least one business endpoint. �Each End point

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. 29

Defining Endpoints <? xml version="1. 0" encoding="utf-8" ? > <configuration xmlns="http: //schemas. microsoft. com/.

Defining Endpoints <? xml version="1. 0" encoding="utf-8" ? > <configuration xmlns="http: //schemas. microsoft. com/. Net. Configuration/v 2. 0 "> <system. service. Model> <services> <service. Type="Calculator. Service"> <endpoint address="Calculator" binding. Section. Name="basic. Profile. Binding" contract. Type="ICalculator" /> </services> </system. service. Model> </configuration>

Hosting � WCF services can not exist in void. � It must be hosted.

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. Host can be provided by IIS Developer as part of application Windows activation service Microsoft Innovation & Practice Team, MSCo. E 31

Message patterns 32

Message patterns 32

WCF Programming Model 33

WCF Programming Model 33

Steps in creating WCF Service Defining. Net service interface to serve as the Service

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. 34

WCF basic task cycle 1. Defining Service Contract 5. Building Clients 4. Hosting Services

WCF basic task cycle 1. Defining Service Contract 5. Building Clients 4. Hosting Services 2. Implem enting Service Contract 3. Configur ing Services 35

WCF Thank You 36

WCF Thank You 36