Windows Communication Foundation Jim Fawcett CSE 681 SW

  • Slides: 30
Download presentation
Windows Communication Foundation Jim Fawcett CSE 681 – SW Modeling & Analysis Summer 2008

Windows Communication Foundation Jim Fawcett CSE 681 – SW Modeling & Analysis Summer 2008

References • Programming “INDIGO”, David Pallmann, Microsoft Press, 2005 • Windows Communication Foundation Unleashed,

References • Programming “INDIGO”, David Pallmann, Microsoft Press, 2005 • Windows Communication Foundation Unleashed, Mc. Murtry, Mercuri, Watling, Winkler, SAMS, 2007 • Pro WCF, Peiris and Mulder, apress, 2007 • MSDN WCF Root Page • WCF Feature Details • Distributed. NET Learn ABCs Of Programming WCF • Service Station Serialization in Windows Communication Foundation • Service Station WCF Messaging Fundamentals • Windows Communication Foundation Glossary • Windows Communication Foundation Tools 2

References – Activation & Channels • • • How to Access WCF Services with

References – Activation & Channels • • • How to Access WCF Services with One-Way and Request-Reply Contracts How to Access Services with a Duplex Contract Sessions, Instancing, and Concurrency WCF Essentials Instance Management WCF Essentials One-Way Calls, Callbacks, Events

References – Web Model How to Create a Basic Web-Style Service WCF Web Programming

References – Web Model How to Create a Basic Web-Style Service WCF Web Programming Model Overview Web Programming Model WCF Web Programming Object Model WCF Syndication HTTP Programming with WCF and the. NET Framework 3. 5 • Creating WCF AJAX Services without ASP. NET • Creating WCF Services for ASP. NET AJAX • • •

References – Odds and Ends • • Accessing Services Using a Clients Client Architecture

References – Odds and Ends • • Accessing Services Using a Clients Client Architecture Client Configuration Call WCF Service Operations Asynchronously A Performance Comparison Security in WCF

What is WCF? • Provides software services on machines, networks, and across the internet

What is WCF? • Provides software services on machines, networks, and across the internet • Unified programming model for all of these • Supported natively on Windows Vista – Requires installation on XP • Not available on other platforms – Mono? – Dot. Gnu? – Mac OSX ? 6

Integration into. Net 3 • One model for distributed systems decomposes into presentation layer,

Integration into. Net 3 • One model for distributed systems decomposes into presentation layer, application logic layer, and data layer, all bound together with communication. • • Presentation: Data: Communic: Applic. Logic: WPF, Silverlight with Asp. Net LINQ - binds views to storage WCF – local, network, internet Custom designs 7

WCF Design Principles • Boundaries are explicit – No attempt to hide communication •

WCF Design Principles • Boundaries are explicit – No attempt to hide communication • Services are autonomous – Deployed, managed, and versioned independently • Services share contracts and schemas, not types – Contracts define behavior, schemas define data • Compatibility is policy-based – Policy supports separation of behavior from access constraints 8

Essential Pieces of WCF • Contracts for services, data, and messages – A contract

Essential Pieces of WCF • Contracts for services, data, and messages – A contract is simply an interface declaration • Service, Data, and Message definitions – Class implementations • Configurations defined programmatically or declaratively – config files. • A host process (can be self hosted) – IIS, Windows Executable, Windows Service, or WAS • . Net Framework (3. 5) Classes provide support for all of the above. 9

Look and Feel of WCF • Convergence of programming models – – Just like

Look and Feel of WCF • Convergence of programming models – – Just like web services Similar to. Net Remoting Sockets on steriods Hosting for local, network, and web • Communication models – Remote Procedure Call (RPC) with optional data models – Message passing – One way, request and wait for reply, asynchronous full duplex 10

WCF Architecture 11

WCF Architecture 11

Service. Model Namespace • Bindings, Channels, Endpoints, Messages, Serialization • Activation, Concurrency, Hosting, Security,

Service. Model Namespace • Bindings, Channels, Endpoints, Messages, Serialization • Activation, Concurrency, Hosting, Security, Sessions • Queuing, Transactions • Exceptions 12

Principle Parts of a WCF Service • Contract – An interface defining services rendered

Principle Parts of a WCF Service • Contract – An interface defining services rendered – Service, Data, Message • Endpoints – Address: http: //localhost/Calculator/service – Binding: ws. Http. Binding – Contract: ICalculator • Implementation – One or more classes that implement the contract interfaces. May also include hosting code. 13

WCF Service Files • IService. cs – Interface(s) that define a service, data, or

WCF Service Files • IService. cs – Interface(s) that define a service, data, or message contract • Service. cs – Implement the service’s functionality • Service. svc – Markup file (with one line) used for services hosted in IIS • Configuration files that declare service attributes, endpoints, and policy – App. config (self hosted) contains service model markup – Web. config (hosted in IIS) has web server policy markup plus service model markup, as in App. config 14

Service service. Model Markup • <system. service. Model> <services> <service name=“my. Svc. Name” behavior.

Service service. Model Markup • <system. service. Model> <services> <service name=“my. Svc. Name” behavior. Configuration=“…”> <endpoint address=“” binding=“ws. Http. Binding” contract=“my. Namespace. my. Interface” /> <!-- can expose additional endpoints here --> <endpoint address=“mex” binding=“mex. Http. Binding” contract=“IMetadata. Exchange” /> </services> <behaviors> <service. Behaviors> <behavior name=“my. Namespace. my. Svc. Name. Behavior”> <service. Meta. Data http. Get. Enabled=“true” /> <service. Debug include. Exception. Detail. In. Faults=“false” /> </behavior> </service. Behaviors> </behaviors> </system. service. Model> 15

Channels • Channels are the vehicles that transport messages. They provide: – Transport protocols

Channels • Channels are the vehicles that transport messages. They provide: – Transport protocols via bindings • Http, ws. Http, Tcp, MSMQ, named pipes – Encoding and Encryption – Reliable sessions – Communication modes • Simplex, duplex, send and wait – Security modes 16

WCF Bindings Binding Interoperability Mode of Security (Default) Session (Default) Transactions Duplex Basic. Http.

WCF Bindings Binding Interoperability Mode of Security (Default) Session (Default) Transactions Duplex Basic. Http. Binding Basic Profile 1. 1 (None), Transport, Message, Mixed None, (None) n/a WSHttp. Binding WS None, Transport, (Message), Mixed (None), Transport, Reliable Session (None), Yes n/a WS 2007 Http. Binding WS-Security, WS-Trust, WS None, Transport, (Message), -Secure. Conversation, WSMixed Security. Policy (None), Transport, Reliable Session (None), Yes n/a WSDual. Http. Binding WS None, (Message) (Reliable Session) (None), Yes WSFederation. Http. Binding WS-Federation None, (Message), Mixed (None), Reliable Session (None), Yes No WS 2007 Federation. Http. Binding WS-Federation None, (Message), Mixed (None), Reliable Session (None), Yes No Net. Tcp. Binding . NET None, (Transport), Message, Mixed Reliable Session, (Transport) (None), Yes Net. Named. Pipe. Binding . NET None, (Transport) (None), Yes Net. Msmq. Binding . NET None, Message, (Transport), Both (None), Yes No Net. Peer. Tcp. Binding Peer None, Message, (Transport), Mixed (None) Yes Msmq. Integration. Binding MSMQ None, (Transport) (None), Yes n/a 17

Interoperability • Channel protocols determine interoperability with other platforms: – – Basic. Http. Binding

Interoperability • Channel protocols determine interoperability with other platforms: – – Basic. Http. Binding universal interoperability ws. Http. Binding platforms that use ws extensions net. Tcp. Binding . Net on both ends MSMQ WCF to pre WCF windows platforms 18

Hosting • Self Host – Service has a Main entry point, runs in its

Hosting • Self Host – Service has a Main entry point, runs in its own process. • Internet Information Server (IIS) – Basic. Http. Binding provides a web service. – ws. Http. Binding provides web service with ws* extensions. • Windows Activation Service (WAS) – Uses virtual directory, like web service. 19

Service Behaviors • Instancing: – – Singleton: one instance for all clients Per call:

Service Behaviors • Instancing: – – Singleton: one instance for all clients Per call: one instance per service call Private session: one instance per client session Shared session: one instance per session shared between clients • Concurrency models for instances: – Single: one thread at a time accesses instance – Multiple: more than one thread may enter instance – Reentrant: threads make recursive calls without deadlock 20

Other Service Behaviors • Throttling: – Limits on number of messages, instances, and threads

Other Service Behaviors • Throttling: – Limits on number of messages, instances, and threads a service can process simultaneously • Error handling: – Options to handle, let framework handle, and report to client • Metadata: – Services can be self-describing, providing MEX endpoints • Lifetime: – Can specify session duration, service operations to initiate sessions and others to terminate sessions • Security: – Can specify message confidentiality, integrity, authentication, authorization, auditing, and replay detection. 21

Structuring Service Code Service Class Attribute Service contract interface [Service. Contract] Service operation method

Structuring Service Code Service Class Attribute Service contract interface [Service. Contract] Service operation method [Operation. Contract] Implementation class [Service. Behavior] Derive from contract interface Implementation method [Operation. Behavior] Data Contract class [Data. Contract] class [Data. Member] member Message Contract interface [Message. Contract] interface [Message. Header] member [Message. Body] member 22

Building Clients • Build proxy with svcutil – Visual Studio will do that if

Building Clients • Build proxy with svcutil – Visual Studio will do that if you add a service or web reference – Proxy code is in a subdirectory under the project. • Add proxy code to project • Add “using System. Service. Model” to client code • Build and run 23

Generating Proxies • Svc. Util. exe generates code: – from a mex endpoint: svcutil

Generating Proxies • Svc. Util. exe generates code: – from a mex endpoint: svcutil http: //localhost/my. Service – from WSDL or XSD files: svcutil my. Service. wsdl • Svc. Util. exe generates WSDL and XSD files from a service library: – svcutil my. Service. dll 24

Channel Model • You can create a channel programmatically – In this case you

Channel Model • You can create a channel programmatically – In this case you access the channel directly without the need of a proxy. • All of the configuration normally done with a Web. config or App. config can also be done programmatically. 25

Types of WCF Contracts • WCF supports: – Service contracts • Supports RPCs with

Types of WCF Contracts • WCF supports: – Service contracts • Supports RPCs with native data types – Data contracts • Data contracts provide definitions of user defined data structures for transmission through RPCs – Message contracts • Message contracts support message passing • Instead of calling functions send and receive messages 26

27

27

WCF Samples • Microsoft has provided a large set of very interesting samples: –

WCF Samples • Microsoft has provided a large set of very interesting samples: – WCF Samples home: http: //msdn. microsoft. com/en-us/library/ms 751514. aspx – Setup instructions here: http: //msdn. microsoft. com/en-us/library/ms 751402. aspx – Download here: http: //www. microsoft. com/downloads/details. aspx? Family. ID=0043041 F-95 D 6 -4 EB 7966 A-C 21 A 737 E 193 A&displaylang=en – Note: • • Samples use a single virtual directory, created by the setup process Builds clear the virtual directory and copy built sample files Initial setup installs developer certificate, required to run SSL In Vista, must Run Visual Studio as administrator 28

White Papers • The following two white papers, by David Chappell plus the Microsoft

White Papers • The following two white papers, by David Chappell plus the Microsoft samples are a great help learning WCF. – www. davidchappell. com/articles/white_papers/Introducing_WCF_in_. Net_Framework_3. 5_v 1. 0. docx – www. davidchappell. com/articles/white_papers/WCF_Diversity_v 1. 0. d ocx 29

End of Presentation 30

End of Presentation 30