Presentation is loading. Please wait.

Presentation is loading. Please wait.

WCF Intro Scott Reed Owner - Brain Hz Software Instructor – DevelopMentor

Similar presentations


Presentation on theme: "WCF Intro Scott Reed Owner - Brain Hz Software Instructor – DevelopMentor"— Presentation transcript:

1 WCF Intro Scott Reed Owner - Brain Hz Software scott@brainhzsoftware.com Instructor – DevelopMentor scottr@develop.com

2 Agenda Why WCF? Architecture Programmatic client and service Moving to configuration Sharing contracts Summary

3 Before WCF TechnologyProsCons SocketsFlexibleCode everything RPCImperative request/replySimplistic, synchronous DCOMTrxs, SecurityComplex, hard to debug/maintain.NET RemotingEasy, configurable, extensible No interoperability ASMX Web ServicesEasy, interoperableSimplistic, Security=SSL only WSE 2.0/3.0Added message securityNot as easy, Verbose, still lacking MSMQAsync, solves availabilityExplicit message passing Clearly not an enabling technology, instead it is unifying

4 WCF Design goal Design goal: – To be the best way to get any two pieces of software to communicate under any circumstances To achieve this had to abstract communication – Services are programs that exchange messages – Lower layer sends messages through channels

5 Messages Packaged data Abstraction of a SOAP message – Xml InfoSet not actually XML Created using factory method – Message.CreateMessage

6 Channels Channel transmit those messages Channels together form a stack Protocol channels can be layered on top – Provide services like reliability and security Encoder changes Message to byte[] Transport channel actually sends the bytes

7 Channel Stack óöu»×{ÊêCÌã³û¢Ì\ÓÒÐ(02 Encoder Transport Channel Protocol Encoder Transport Channel Protocol óöu»×{ÊêCÌã³û¢Ì\ÓÒÐ(02

8 Programming in the Channel Layer Explicit message passing like in sockets or MSMQ – What happened to easy? void ChannelListen() { IChannelListener listener = GetListener(); listener.Open(); while (listener.WaitForChannel()) { IReplyChannel channel = listener.AcceptChannel(); channel.Open(); RequestContext request = channel.ReceiveRequest(); Message reply = HandleMessage(request.RequestMessage); request.Reply(reply); request.Close(); channel.Close(); } void ChannelListen() { IChannelListener listener = GetListener(); listener.Open(); while (listener.WaitForChannel()) { IReplyChannel channel = listener.AcceptChannel(); channel.Open(); RequestContext request = channel.ReceiveRequest(); Message reply = HandleMessage(request.RequestMessage); request.Reply(reply); request.Close(); channel.Close(); }

9 Service Model Layer Sits on top of Channel Layer and hides it Allows method invocation of strongly typed parameters Uses serialization to translate objects into messages

10 The Big Picture protocol encoder transport protocol encoder transport serializer proxy dispatcher service object Service Model Layer Channel Layer

11 Endpoint Clients talk to endpoints, and services expose endpoints Address Binding Contract

12 BCA BCA BCA BCA BCA ClientService

13 WCF in all its glory Business Partner Customer wsHttpBinding (feature rich) basicHttpBinding (compatibility) netTcpBinding (performance) netMsmqBinding (batch processing) netNamedPipeBinding (local, fast) Browser webHttpBinding (AJAX, JSON…)

14 Hosting Need something to listen for incoming connections (a host) WCF is host independent (by default) Self host (Console, NT Service, Forms/WPF App) – Use the ServiceHost class (Open and Close) IIS/WAS hosted – Use a.svc file (just like ASMX) WCF provided host for testing * – WcfServiceHost

15 Step by step Define the contract Implement the contract Host the service Expose endpoints Optionally expose metadata

16 Demo Writing a programmatic client and a service

17 Configuration Why do it in config? – So you don’t have to recompile Everything you do in code can be done in config (almost)

18 Demo (revisited) Changing to a config file

19 Sharing contracts Both the client and the service need to know the types and methods listed in the contract There are two ways to accomplish this: – Share types (ala Remoting) – Share schema (ala ASMX)

20 Demo (revisited again) Exposing metadata (base and explicit) Generating a proxy

21 Summary WCF unifies communications technology Architected in two layers: – Channel layer and Service Model layer Endpoints are ABCs Two ways to share contract (type and schema)


Download ppt "WCF Intro Scott Reed Owner - Brain Hz Software Instructor – DevelopMentor"

Similar presentations


Ads by Google