1 / 42

Introduction to WCF Architecture and Extensibility

Introduction to WCF Architecture and Extensibility. Risman Adnan ISV Lead, Microsoft Indonesia rismana@microsoft.com http://geeks.netindonesia.net/blogs/risman. My Motivation. Explain how WCF works Give you 1 st experience with WCF & VS 2008 Duplex / Request reply session  .

seoras
Download Presentation

Introduction to WCF Architecture and Extensibility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to WCFArchitecture and Extensibility Risman Adnan ISV Lead, Microsoft Indonesia rismana@microsoft.com http://geeks.netindonesia.net/blogs/risman

  2. My Motivation • Explain how WCF works • Give you 1st experience with WCF & VS 2008 • Duplex / Request reply session 

  3. Our problem Volume of Software Increases Software Ability to Adapt Decreases!!! Time

  4. WCF Approach

  5. WCF in a Nutshell Address Binding Contract Behavior Request/Response InstancingBehavior HTTPTransport WS-SecurityProtocol ConcurrencyBehavior http://... Peer Transport net.p2p://... Throttling Behavior WS-RMProtocol TCP Transport net.tcp://... MetadataBehavior NamedPipeTransport WS-CoordProtocol One-Way net.pipe://... Error Behavior TransactionBehavior MSMQTransport DuplexChannel net.msmq://... CustomBehavior SecurityBehavior Duplex CustomTransport CustomProtocol xxx://... Externally visible, per-endpoint Opaque, per-service, endpoint, or operation

  6. C C C B B B A A A ArchitectureProgramming Model Client Service Bv Bv Message Bv Bv Address Binding Contract (Where) (How) (What)

  7. C C B B A A ArchitectureLayering Service Bv Bv

  8. C C C B B B A A A Architecture: Description & Runtime Client Service Bv Bv Message Bv Bv ChannelFactory<T> ServiceHost Description Runtime Description Runtime

  9. Type Loader Programming Model Description Config Config Loader

  10. WSDL/Policy Metadata Import Metadata Export Type Loader Description Runtime Programming Model Runtime Builder Description Code Spit Config Gen Config Loader Config

  11. Description ServiceDescription ServiceEndpoint * Binding ContractDescription OperationDescription * * 1 to n

  12. Description ServiceDescription public class CalculatorService : ICalculator { ... } Name Namespace Config Name Service Type Behaviors

  13. Description ServiceDescription <system.serviceModel> <services> <service name="CalculatorService"> <endpoint address="http://..." binding="wsHttpBinding” contract="ICalculator" /> </service> </services> </system.serviceModel> ServiceEndpoint * EndpointAddress ListenURI Behaviors

  14. Description <system.serviceModel> <services> <service name="CalculatorService"> <endpoint address="http://..." binding="customBinding” bindingConfiguration="RelHttp" contract="ICalculator" /> </service> </services> <customBinding> <binding name=“RelHttp" > <reliableSession/> <httpTransport/> </binding> </bindings> </system.serviceModel> ServiceDescription <system.serviceModel> <services> <service name="CalculatorService"> <endpoint address="http://..." binding="wsHttpBinding” contract="ICalculator" /> </service> </services> </system.serviceModel> ServiceEndpoint * Binding Name BindingElement[]

  15. Description ServiceDescription [ServiceContract(Namespace=“...")] public interface ICalculator { [OperationContract] double Add(double n1, double n2); [OperationContract] double Sub(double n1, double n2); } ServiceEndpoint * Binding ContractDescription Session ContractName Namespace Behaviors

  16. Description ServiceDescription [ServiceContract(Namespace=“...")] public interface ICalculator { [OperationContract] double Add(double n1, double n2); [OperationContract] double Sub(double n1, double n2); } ServiceEndpoint * Binding OperationDescription * ContractDescription Name IsOneWay Behaviors … OperationDescription *

  17. Channel Model

  18. ArchitectureChannel Stack Client Dispatcher Protocol2 Protocol2 Protocol1 Protocol1 Transport Transport

  19. Description ServiceDescription <system.serviceModel> <!–- endpoints configured here --> <bindings> <customBinding> <binding name=“ReliableHttp" > <reliableSession/> <httpTransport/> </binding> </bindings> </system.serviceModel> CustomBinding binding = new CustomBinding(); binding.Name = “ReliableHttp”; binding.Elements.Add( new ReliableSessionBindingElement()); binding.Elements.Add( new HttpTransportBindingElement()); //create a channel listener or //create a ServiceEndpoint ServiceEndpoint * Binding Name BindingElement[]

  20. User Bindings public class MyReliableHttpBinding : Binding { // BindingElement members // ctor initializing BindingElements // any properties you want to expose as settings // override Scheme public override BindingElementCollection CreateBindingElements() { BindingElementCollectionbindingElements = new BindingElementCollection(); bindingElements.Add(this.httpsTransport); bindingElements.Add(this.reliableSession); return bindingElements.Clone(); } }

  21. CommunicationObject • Predictable state transitions • Unified communication resource model • Default implementation • Events • Timeouts • Exception Contract Created Opening Opened Closing Closed Faulted

  22. Bindings, Listeners, Factories, and Channels Binding Binding BuildChannel Factory(Uri) BuildChannel Listener(Uri) Open() Open() ChannelListener ChannelListener ChannelListener ChannelListener ChannelListener ChannelFactory Create Channel() Accept Channel() Open() Open() Channel Channel Send() Receive()

  23. Service Model

  24. ServiceHost • Constructor: Service Type • Features • AddServiceEndpoint() overloads • Description • CommunicationObject • TimeOuts: Open, Close • Events • Open()/Close()/Abort()

  25. Working With ServiceHost • “Outside-In” • new ServiceHost() • Mess with it directly • Open() it • “Inside-Out” • Subclass ServiceHost • Implement OnOpening() • new ServiceHost() • Open() it

  26. ServiceHost.ctor 1. Reflect Over T .ctor(…); ServiceDescription [ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple)] public class CalculatorService : ICalculator { [OperationContract] [OperationBehavior(TransactionScopeRequired=true)] double Add(double n1, double n2){...} } ContractDescription OperationDescription *

  27. 1. Reflect Over T ServiceHost.ctor .ctor(…); ServiceDescription 2. Load Config <system.serviceModel> <services> <service name="CalculatorService" behaviorConfiguration="Bv1"> <!-- endpoint config --> </service> </services> <behaviors> <serviceBehaviors> <behavior name=“Bv1"> <serviceMetadata httpGetEnabled="True"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> ServiceEndpoint * Binding <system.serviceModel> <services> <service name="CalculatorService"> <endpoint address="http://..." binding="wsHttpBinding” contract="ICalculator" /> </service> </services> </system.serviceModel> ContractDescription OperationDescription *

  28. 1. Reflect Over T 2. Load Config .Description { get; } ServiceHost .ctor(…); 3. Build Runtime .Open();

  29. ServiceDescription ServiceDescription ServiceEndpoint * Binding ServiceEndpoint ContractDescription Binding OperationDescription * ContractDescription OperationDescription OperationDescription OperationDescription

  30. ServiceDescription ChannelDispatcher * ServiceEndpoint EndpointDispatcher ContractDescription Binding DispatchRuntime OperationDescription DispatchOperation OperationDescription DispatchOperation OperationDescription DispatchOperation Add(…) Sub(…) Mul(…)

  31. ServiceDescription ServiceDescription ChannelDispatcher * ChannelDispatcher * ServiceEndpoint EndpointDispatcher ServiceEndpoint ServiceEndpoint EndpointDispatcher ContractDescription Binding DispatchRuntime ContractDescription Binding DispatchRuntime OperationDescription DispatchOperation OperationDescription DispatchOperation OperationDescription DispatchOperation OperationDescription DispatchOperation OperationDescription DispatchOperation OperationDescription DispatchOperation Add(…) Sub(…) Mul(…)

  32. 1. Reflect Over T 2. Load Config .Description { get; } .Open(); ServiceHost .ctor(…); 3. Build Runtime

  33. Behaviors [MyBehavior] 1. Reflect Over T .ctor(…); <myBehavior /> 2. Load Config .Description.Behaviors.Add(new MyBehavior()); .Description 3. Build Runtime 4. Apply Behaviors Behaviors .Open(); 5. Open Resources

  34. Behaviors public interface I*Behavior { void Validate(...); void AddBindingParameters(...); void ApplyDispatchBehavior(...); void ApplyClientBehavior(...); }

  35. Channel ChannelDispatcher * EndpointDispatcher DispatchRuntime DispatchRuntime DispatchOperation DispatchOperation DispatchOperation Add(…) Sub(…) Mul(…)

  36. Channel DispatchRuntime DispatchOperation DispatchOperation DispatchOperation Add(…) Sub(…) Mul(…)

  37. Message Inspection Extending the DispatcherOverview DispatchOperation Add(…) DispatchOperation Sub(…) Channel DispatchRuntime DispatchOperation Mul(…) public interface IDispatchMessageInspector { object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContextinstanceContext); void BeforeSendReply(ref Message reply, object correlationState); }

  38. Parameter Inspection Message Formatting Message Inspection Operation Selector Operation Invoker Extending the DispatcherOverview DispatchOperation Add(…) DispatchOperation Sub(…) Channel DispatchRuntime DispatchOperation Mul(…) public interface IOperationInvoker { object Invoke(object instance, object[] inputs, out object[] outs); IAsyncResultInvokeBegin(object instance, object[] inputs, ...); object InvokeEnd(object instance, out object[] outputs, ...); } public interface IDispatchFormatter { void DeserializeRequest(Message message, object[] parameters); Message SerializeReply(MessageVersionmessageVersion, object[] parameters, object result); } public interface IParameterInspector { object BeforeCall(string operationName, object[] inputs); void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState); } public interface IDispatchMessageInspector { object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContextinstanceContext); void BeforeSendReply(ref Message reply, object correlationState); } public interface IDispatchOperationSelector { string SelectOperation(ref Message message); }

  39. .Description.Behaviors.Add(new MyBehavior()); <myBehavior /> [MyBehavior] Service / Endpoint Behaviors Operation Behaviors Extending the DispatcherBehaviors DispatchOperation Sub(…) Message Formatting Message Inspection Operation Selector Parameter Inspection Operation Invoker Channel DispatchRuntime

  40. Summary • WCF uses a layered architecture: Messaging & Service Model • Description is central • Behaviors participate in description to runtime conversion • Use Behaviors to tweak the runtime: Validation, Throttles, Extensions etc. Programming Model Description Runtime

  41. Community Resources • http://geeks.netindonesia.net • http://www.netfx3.com • http://msdn.microsoft.com • http://www.codeplex.com • http://www.sf.net • http://www.asp.net • http://www.windowsforms.net • http://www.silverlight.net

  42. © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related