Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation.

Similar presentations


Presentation on theme: "Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation."— Presentation transcript:

1 Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation

2 Introducing WCF Windows Vista =>.NET Framework 3.0 Also for Windows XP, 2003 Server & 2007 Not Windows Mobile / Windows CE Unified Service-Oriented Programming Model Replaces / Suplements.NET Remoting DCOM ASP.NET Web services MSMQ (Queued Messaging).NET Enterprise Services Protocol Neutrality and Flexibility http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/wcfroadmap.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/wcfarch.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/wcfroadmap.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/wcfarch.asp

3 Learning WCF WCF much like.NET Remoting / ASP.NET WS Easier / More extensive ITONK will adress key issues of WCF

4 WCF Basic Concepts Remote system (like.NET Remoting) is: Exchanging Messages Using Channels, consisting of Encodeders Transports Also called the Channel layer On top of this is the Service Model Layer

5 WCF Architecture

6 Channels Channels is chain of stacks Much like.NET Remoting Sending messages, being encoded and transported

7 Messages WCF Applications Exchanges Messages Modelled on SOAP messages Envelope, header, body Adressing Messages are smallest unit of transmission Messsages have a SOAP and addressing version

8 Messages Message Exchange Pattern (MEP) One way, request, response, duplex

9 Channels Messages are payload Channels provide transmission stream Protocol channels Independent of transport Extensible Transport channels HTTP, TCP, MSMQ, P2P, Named Pipes Extensible

10 Encoders Text (XML, interop) JSON/POX (XML or JSON, interop) MTOM (XML with binary part, interop) Binary (non-interop)

11 Service Model Layer Channel Layer may be used alone – but low level Service Model Layer Build on top of Channel Layer.NET Typed layer Uses object serialization to generate message XML

12 Endpoints Applications communicates through endpoints Endpoints defined by WCF ABC Address (where is the service) Binding (which transport and encoding to use) Contract (what operations are available)

13 Contracts Uses annotated.NET interfaces

14 Contracts Like in ASP.NET – only expose explict annotated operations

15 Bindings Many Bindings: Interopable basicHttpBinding webHttpBinding wsHttpBinding, wsFederationHttpBinding WCF Specific netTCPBinding netPeerTcpBinding netNamedPipeBinding netMsmqBinding MSMQ interop MsmqlIntegrationBinding Extensible (write your own)

16 WCF Bindings Matrix

17 Choose your Binding Before – you had to choose different middlewares Now – just choose different bindings

18 Hosting Services Two models supported Self-hosting: own process (console, winform) WAS hosting Windows Activation Service Supported by IIS7 Emulated for IIS6 for HTTP/S

19 Self-hosting Make a ServiceHost, Add Endpoints, Call Open

20 Creating a Client Dynamic Proxies supported (like.NET Remoting) Use ChannelFactory for this

21 Specify Endpoint in Config file

22 Behaviors Behaviors can be used to affect the internals of WCF Eg. Transaction Flow Has nothing to do with the wire Many build-in behaviors, but extensible for own Attributes can be used [ServiceBehavior], [OperationBehavior] Configuration file defined behaviors Code defined behaviors

23 Meta Data Two ways of sharing contracts WSDL or Shared Contract DLL

24 Creating Static Proxies Unlike.NET Remoting, which only supports dynamic proxy generation there is also static gen. in WCF Or ”Add Service Reference” in VS

25 Defining the Contract using System.ServiceModel; //a WCF contract defined using an interface [ServiceContract] public interface IMath { [OperationContract] int Add(int x, int y); } using System.ServiceModel; //a WCF contract defined using an interface [ServiceContract] public interface IMath { [OperationContract] int Add(int x, int y); } //the service class implements the interface public class MathService : IMath { public int Add(int x, int y) { return x + y; } } //the service class implements the interface public class MathService : IMath { public int Add(int x, int y) { return x + y; } }

26 Implementing the Service public class WCFServiceApp { public void DefineEndpointProgrammable() { //create a service host for MathService ServiceHost sh = new ServiceHost(typeof(MathService)); //use the AddEndpoint helper method to //create the ServiceEndpoint and add it //to the ServiceDescription sh.AddServiceEndpoint( typeof(IMath), //contract type new WSHttpBinding(), //one of the built-in bindings "http://localhost/MathService/Ep1"); //the endpoint's address //create and open the service runtime sh.Open(); } public void DefineEndpointInConfig() { //create a service host for MathService ServiceHost sh = new ServiceHost (typeof(MathService)); //create and open the service runtime sh.Open(); } public class WCFServiceApp { public void DefineEndpointProgrammable() { //create a service host for MathService ServiceHost sh = new ServiceHost(typeof(MathService)); //use the AddEndpoint helper method to //create the ServiceEndpoint and add it //to the ServiceDescription sh.AddServiceEndpoint( typeof(IMath), //contract type new WSHttpBinding(), //one of the built-in bindings "http://localhost/MathService/Ep1"); //the endpoint's address //create and open the service runtime sh.Open(); } public void DefineEndpointInConfig() { //create a service host for MathService ServiceHost sh = new ServiceHost (typeof(MathService)); //create and open the service runtime sh.Open(); } Create the Service Endpoint Programmatically Create the Service Endpoint Programmatically Create the Service Endpoint Using a Configuration File (see next slide) Create the Service Endpoint Using a Configuration File (see next slide)

27 Configuration File <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <endpoint address="http://localhost/MathService/Ep1" binding="wsHttpBinding" contract="IMath"/> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <endpoint address="http://localhost/MathService/Ep1" binding="wsHttpBinding" contract="IMath"/>

28 Implementing the Client Using Static Proxy //this class is generated by svcutil.exe //from the service's metadata //generated config is not shown here public class MathProxy : IMath {... } public class WCFClientApp { public void SendMessageToEndpoint() { //this uses a proxy class that was //created by svcutil.exe from the service's metadata MathProxy proxy = new MathProxy(); int result = proxy.Add(35, 7); proxy.Close(); } //this class is generated by svcutil.exe //from the service's metadata //generated config is not shown here public class MathProxy : IMath {... } public class WCFClientApp { public void SendMessageToEndpoint() { //this uses a proxy class that was //created by svcutil.exe from the service's metadata MathProxy proxy = new MathProxy(); int result = proxy.Add(35, 7); proxy.Close(); }

29 Implementing the Client Using Dynamic Proxy public class WCFClientApp { public void SendMessageToEndpointUsingChannel() { //this uses ChannelFactory to create the channel //you must specify the address, the binding and //the contract type (IMath) ChannelFactory factory=new ChannelFactory ( new WSHttpBinding(), new EndpointAddress("http://localhost/MathService/Ep1")); IMath channel=factory.CreateChannel(); int result=channel.Add(35,7); factory.Close(); } public class WCFClientApp { public void SendMessageToEndpointUsingChannel() { //this uses ChannelFactory to create the channel //you must specify the address, the binding and //the contract type (IMath) ChannelFactory factory=new ChannelFactory ( new WSHttpBinding(), new EndpointAddress("http://localhost/MathService/Ep1")); IMath channel=factory.CreateChannel(); int result=channel.Add(35,7); factory.Close(); }

30 Data transfer objects WCF support DTO’s Use [DataContract] decoration All serializable objects may be used instead -> less configurable

31 Plenum Discussion Use 5 minutes in your groups: Differences with Web services /.NET Remoting Strength over Web services /.NET Remoting Weaknesses compared to –”-? Plenum: 5 minutes discussion of findings


Download ppt "Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation."

Similar presentations


Ads by Google