presentation 24: windows communication foundation introduced objektorienteret netværkskommunikation
TRANSCRIPT
![Page 1: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/1.jpg)
Presentation 24:Windows Communication Foundation
Introduced
Objektorienteret Netværkskommunikation
![Page 2: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/2.jpg)
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
![Page 3: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/3.jpg)
Learning WCF
• WCF much like .NET Remoting / ASP.NET WS
• Easier / More extensive
• ITONK will adress key issues of WCF
![Page 4: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/4.jpg)
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
![Page 5: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/5.jpg)
WCF Architecture
![Page 6: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/6.jpg)
Channels
• Channels is chain of stacks • Much like .NET Remoting• Sending messages, being encoded and transported
![Page 7: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/7.jpg)
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
![Page 8: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/8.jpg)
Messages
• Message Exchange Pattern (MEP)• One way, request, response, duplex
![Page 9: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/9.jpg)
Channels
• Messages are payload• Channels provide transmission stream• Protocol channels
• Independent of transport
• Extensible
• Transport channels• HTTP, TCP, MSMQ, P2P, Named Pipes
• Extensible
![Page 10: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/10.jpg)
Encoders
• Text (XML, interop) • JSON/POX (XML or JSON, interop)• MTOM (XML with binary part, interop)• Binary (non-interop)
![Page 11: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/11.jpg)
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
![Page 12: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/12.jpg)
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)
![Page 13: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/13.jpg)
Contracts
• Uses annotated .NET interfaces
![Page 14: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/14.jpg)
Contracts
• Like in ASP.NET – only expose explict annotated operations
![Page 15: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/15.jpg)
Bindings
• Many Bindings:
• Interopable• basicHttpBinding• webHttpBinding• wsHttpBinding, wsFederationHttpBinding
• WCF Specific• netTCPBinding• netPeerTcpBinding• netNamedPipeBinding• netMsmqBinding
• MSMQ interop• MsmqlIntegrationBinding
• Extensible (write your own)
![Page 16: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/16.jpg)
WCF Bindings Matrix
![Page 17: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/17.jpg)
Choose your Binding
• Before – you had to choose different middlewares• Now – just choose different bindings
![Page 18: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/18.jpg)
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
![Page 19: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/19.jpg)
Self-hosting
• Make a ServiceHost, Add Endpoints, Call Open
![Page 20: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/20.jpg)
Creating a Client
• Dynamic Proxies supported (like .NET Remoting)• Use ChannelFactory for this
![Page 21: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/21.jpg)
Specify Endpoint in Config file
![Page 22: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/22.jpg)
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
![Page 23: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/23.jpg)
Meta Data
• Two ways of sharing contracts• WSDL or Shared Contract DLL
![Page 24: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/24.jpg)
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
![Page 25: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/25.jpg)
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 interfacepublic class MathService : IMath{ public int Add(int x, int y) { return x + y; }}
//the service class implements the interfacepublic class MathService : IMath{ public int Add(int x, int y) { return x + y; }}
![Page 26: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/26.jpg)
Implementing the Servicepublic 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 EndpointProgrammatically
Create the Service EndpointProgrammatically
Create the Service Endpoint
Using a ConfigurationFile (see next slide)
Create the Service Endpoint
Using a ConfigurationFile (see next slide)
![Page 27: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/27.jpg)
Configuration File
<!-- configuration file used by above code --><configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.serviceModel> <services> <!-- service element references the service type --> <service type="MathService"> <!-- endpoint element defines the ABC's of the endpoint --> <endpoint address="http://localhost/MathService/Ep1" binding="wsHttpBinding" contract="IMath"/> </service> </services> </system.serviceModel></configuration>
<!-- configuration file used by above code --><configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.serviceModel> <services> <!-- service element references the service type --> <service type="MathService"> <!-- endpoint element defines the ABC's of the endpoint --> <endpoint address="http://localhost/MathService/Ep1" binding="wsHttpBinding" contract="IMath"/> </service> </services> </system.serviceModel></configuration>
![Page 28: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/28.jpg)
Implementing the Client Using Static Proxy
//this class is generated by svcutil.exe//from the service's metadata//generated config is not shown herepublic 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 herepublic 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(); }
![Page 29: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/29.jpg)
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<IMath> factory=new ChannelFactory<IMath>( 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<IMath> factory=new ChannelFactory<IMath>( new WSHttpBinding(), new EndpointAddress("http://localhost/MathService/Ep1")); IMath channel=factory.CreateChannel(); int result=channel.Add(35,7); factory.Close();
}
![Page 30: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/30.jpg)
Data transfer objects
• WCF support DTO’s• Use [DataContract]
decoration• All serializable objects
may be used instead -> less configurable
![Page 31: Presentation 24: Windows Communication Foundation Introduced Objektorienteret Netværkskommunikation](https://reader036.vdocument.in/reader036/viewer/2022062409/5697c0121a28abf838ccc630/html5/thumbnails/31.jpg)
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