Introduction O O O O O O O W C F o o o o o c PV178: Programming for .NET Framework Windows Communication Foundation Vojtech Forejt, forejt@fi.muni.cz Martin Osovsky, osovsky@ics.muni.cz Faculty of Informatics and Institute of Computer Science Masaryk University April 20, 2010 • gji - = = ^ 0 0 , 0 Introduction • O O O O O O D W C F o o o o o c • Applications composed of several processes. • Processes usually communicate via a network. • Java RMI, .NET Remoting, Web services... • Each technology has slightly different purpose. • The technologies are not compatible. • Migrating from one technology to another requires a lot of effort. • - = = ^0 0 , 0 Introduction O 0 O O O O O Servi W C F o o o o o c • Method of development in which systems provide functionality as loosely coupled services • Service - mechanism providing access to one or more capabilities using a prescribed interface and consistent constraints and policies • Each service implements one action (get a weather forecast, book a hotel room, get latest blog posts,...) • Services communicate using predefined protocols. • rji - = = ^0 0 , 0 Introduction O O 0 O O O O Basic W C F o o o o o c • named and anonymous pipes, mailslots • rpc, Ipc, ape... • files • memory mapped files Introduction O O O 0 O O O Mess, W C F o o o o o c • public, private queues • implemented via filesystem • accesible by name e.g. pocitac\jmeno • methods Send, Peek, Receive • all have asynchronous versions Introduction W C F o o o o « o o o o o o o c .NET Remoting • Allows creation of object shared by several applications • Platform specific • Similar to Java RMI Introduction O O O O O 0 O Web W C F o o o o o c • Services communicating over standard internet protocols • Exact behaviour described by standards (SOAP, REST, WSDL, UDDI,...) • Messages are mostly passed as X M L files • Communication between different languages and/or platforms • - = = ^0 0 , 0 Introduction O O O O O O * W C F o o o o o c < o • i l l < 1 • Introduction O O O O O O O 3Win W C F • o o o o c • Framework for building applications that inter-communicate. • From .NET 3.0, under development in Mono. • Follows principles of SOA. • The underlying architecture may not be hard-coded, can be changed using config files. • Namespace System.ServiceModel. Introduction O O O O O O O 1wc W C F o»oooc • Service is a CLR type that exposes a functionality via a set of methods accessible by remote clients • Endpoints - Specify the way in which service communicates with clients • Address - URI • Binding - protocols supported • Contract - functionality supported (methods, types) Introduction O O O O O O O Says where the service is available. Address at which the service awaits incomming messages ://[:port]/[path] • Examples: http://example.com/ServiceA net.msmq://localhost Every endpoint must have unique address • - = = ^0 0 , 0 Introduction o o o o o o o Binding W C F o o o » o c • Says how the service can be accessed • Transport protocol - TCP, HTTP, named pipe, M S M Q , . . . • Message encoding - X M L , binary • Other protocols - for security, reliability. • rjj - = = ^0 0 , 0 Introduction O O O O O O O Binding cont. W C F o o o o « c • W C F provides classes for most commonly used binding types • Web services - BasicHttpBinding, WSHttpBinding, ... • Binary - NetTcpBinding, NetNamedPipeBinding,... Introduction O O O O O O O Se W C F 0 0 0 0 0 « • Says what the service provides • Set of operations that the service exposes • Provided via a class marked with ServiceContractAttribute and its methods with OperationContractAttribute. Introduction O O O O O O O W C F o o o o o c • Used by clients to communicate with services • Hide process of serialization from the client. • Based on the service contract. • rfp> - = = ^0 0 , 0 Introduction o o o o o o o Channels W C F o o o o o c • Facilitate the communication between proxy and service • Channel stack - transport channel, message encoding channel, channels for security,... Introduction O O O O O O O Se W C F o o o o o c • Service is made available through a host process • Internet Information Services • Windows Activation Services • Windows service • Windows Form • Console Introduction O O O O O O O Se W C F o o o o o c • Used to host services not hosted by IIS • Type of a service is passed in constructor • Endpoint are created by AddServiceEndpoint method, or created from config file. • Open and Close methods start and stop listening on the endpoint. • - = = ^0 0 , 0 Introduction O O O O O O O WCF - Structure W C F o o o o o c Client f \ Service Proxy B Channnel(s) A B C V J message • - = = ^ 0 0 , 0 Introduction o o o o o o o Example W C F o o o o o c • SimpleWebService • rfpi - = = o Introduction O O O O O O O W C F o o o o o c • The methods described by service contract may need to use "complex" types. • Data contract describes how a complex type is serialized. • DataContractAttribute is applied to the complex type to be serialized. • DataMemberAttribute is applied to the serialized members. Introduction O O O O O O O WCF in Visual Studio W C F O O O O O t • Rich design time support • Editing of config files • Proxy generation • Service Testing • Example