introduction to Windows Comunication Foundation


Published on

A good slide to to start working in WCF

Published in: Technology
1 Comment
  • I can not download this slide from the linkage provided by the can you please tell me why?
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

introduction to Windows Comunication Foundation

  1. 2. The Windows Communication Foundation
  2. 3. <ul><li>Interoperability & Integration </li></ul><ul><li>Secure, Reliable, Transacted Messaging </li></ul><ul><li>Decoupled, Dynamic Applications </li></ul>The Connectivity Imperative
  3. 4. .NET At The Core
  4. 5. Windows Communication Foundation The Unified Framework For Rapidly Building Service-Oriented Applications
  5. 6. Windows Communication Foundation INTEROPERABILITY PRODUCTIVITY SERVICE-ORIENTED DEVELOPMENT <ul><li>Broad Support for WS-* specifications </li></ul><ul><li>Compatible with existing MS distributed application technologies </li></ul><ul><li>Unifies today’s distributed technologies </li></ul><ul><li>Attribute-based development </li></ul><ul><li>Visual Studio 2005 integration </li></ul><ul><li>Enables development of loosely-coupled services </li></ul><ul><li>Config-based communication </li></ul>
  6. 7. Unified Programming Model Interop with other platforms ASMX Attribute- Based Programming Enterprise Services WS-* Protocol Support WSE Message- Oriented Programming System.Messaging Extensibility Location transparency .NET Remoting
  7. 8. WS-* Protocol Support XML Messaging Security Transactions Reliable Messaging Metadata
  8. 9. Investment Protection SIDE-BY-SIDE Interop UPGRADE
  10. 11. From Objects to Services <ul><li>Polymorphism </li></ul><ul><li>Encapsulation </li></ul><ul><li>Subclassing </li></ul><ul><li>Message-based </li></ul><ul><li>Schema+Contract+Policy </li></ul><ul><li>Broad Interop </li></ul><ul><li>Location Transparent </li></ul><ul><li>Tight Coupling </li></ul><ul><li>Runtime Metadata </li></ul>Object-Oriented Service-Oriented Component-Oriented 1980s 2000s 1990s
  11. 12. Four Tenets of Service Orientation SERVICE ORIENTATION Compatibility Based On Policy Share Schema & Contract, Not Class Services Are Autonomous Boundaries Are Explicit
  12. 13. Conventional Web Services <ul><ul><li>The old way of easily exposing components (ASMX): </li></ul></ul>.NET Component ASMX Web Service HTTP Client
  13. 14. WCF Services <ul><ul><li>The new way of easily exposing components (WCF): </li></ul></ul>.NET Component HTTP Host TCP Host ICP Host MSMQ Host HTTP Client TCP Client ICP Client MSMQ Client Service Contract
  14. 15. The Windows Communication Foundation
  15. 16. Main Design Goal <ul><li>Unification </li></ul><ul><ul><li>Unify today’s distributed technology stacks </li></ul></ul><ul><ul><li>Talk on-machine, cross-machine, cross-networks & Internet </li></ul></ul><ul><li>Productivity </li></ul><ul><ul><li>Codify best practices for building distributed apps </li></ul></ul><ul><ul><li>Maximize productivity </li></ul></ul><ul><li>Integration </li></ul><ul><ul><li>Interoperate with apps running on other platforms </li></ul></ul><ul><ul><li>Integrate with Microsoft’s existing technologies </li></ul></ul>
  16. 17. Agenda <ul><li>Introduction </li></ul><ul><li>Overview </li></ul><ul><ul><li>Main Concepts </li></ul></ul><ul><ul><li>Hello World </li></ul></ul><ul><li>Contracts </li></ul><ul><li>Bindings </li></ul><ul><li>Behaviours </li></ul><ul><li>Summary </li></ul>
  17. 18. Callers and Services Caller Service
  18. 19. Endpoints Caller Service Endpoint Endpoint Endpoint Endpoint
  19. 20. Address, Binding, Contract Service Caller C B A C B A A B C Address Where? Contract What? Binding How? C B A
  20. 21. Creating Endpoints Service Service Host Caller Proxy or ChannelFactory A B C C B A C B A C B A
  21. 22. Exposing & Configuring Endpoints proxy.cs Caller app/web.config GetMetadata WSDL Service ? C B A C B A C B A C B A C B A C B A
  22. 23. Hello World
  23. 24. Agenda <ul><li>Introduction </li></ul><ul><li>Overview </li></ul><ul><li>Contracts </li></ul><ul><ul><li>Service </li></ul></ul><ul><ul><li>Data </li></ul></ul><ul><ul><li>Message </li></ul></ul><ul><li>Bindings </li></ul><ul><li>Behaviours </li></ul><ul><ul><li>Instancing </li></ul></ul><ul><li>Summary </li></ul>
  24. 25. WCF Contracts Overview <ul><li>Service Contracts </li></ul><ul><ul><li>Describe the operations a service can perform </li></ul></ul><ul><ul><li>Map CLR types to WSDL </li></ul></ul><ul><li>Data Contracts </li></ul><ul><ul><li>Describes a data structure </li></ul></ul><ul><ul><li>Maps CLR types to XSD </li></ul></ul><ul><li>Message Contracts </li></ul><ul><ul><li>Defines the structure of the message on the wire </li></ul></ul><ul><ul><li>Maps CLR types to SOAP messages </li></ul></ul>
  25. 26. Service Contract [ServiceContract] public interface ICalculator { [OperationContract] int DoMath(int a, int b, string op); }
  26. 27. Service Contract An Opt-In Model [ServiceContract] public interface ICalculator { [OperationContract] int DoMath(int a, int b, string op); // Not exposed as part of the external contract :-) void MethodRequiredForImplementation(bool b); }
  27. 28. Operations Types Message DoXmlMath( Message m); Untyped (“Universal”) MathResponse DoMsgMath( MathRequest msg); int DoParamsMath( int a, int b, string op ); Typed Message Parameterized Operations (shorthand for TM)
  28. 29. Service Contract: Names [ServiceContract( Namespace =&quot;http://TechEd.WCF.Intro&quot;)] public interface IGreetings { [OperationContract( Name =“SayHello&quot;, Action =&quot;http://TechEd.WCF.Intro/HelloRequest&quot;, ReplyAction =&quot;http://TechEd.WCF.Intro/HelloResponse&quot;)] string Greet(string name); [OperationContractAttribute( Action = &quot;*&quot; )] void UnrecognizedMessageHandler( Message msg ); } class GreetingService : IGreetings { public string Greet(string name) { return “Hello, &quot; + name; } public void UnrecognizedMessageHandler(Message msg) { Console.WriteLine(&quot;Unrecognized message: &quot; + msg.ToString()); } }
  29. 30. Modeling Request/Reply Operations <ul><li>On the wire everything is asynchronous </li></ul><ul><li>Therefore, Request and Reply correlation can be modeled in 2 ways </li></ul><ul><li>It can be modeled either as a synchronous (blocking) method call </li></ul><ul><li>or using the .NET Async-Pattern </li></ul><ul><li>The implementation on the client and the service can be different ! </li></ul>[OperationContract] MathResponse DoMsgMath(MathRequest msg); [OperationContrac t(AsyncPattern=true) ] IAsyncResult BeginDoMsgMath(MathRequest msg, AsyncCallback cb, object state ) ; MathResponse EndDoMsgMath(IAsyncResult call);
  30. 31. Service Contract: OneWay [ServiceContract] public interface IOneWayCalculator { [OperationContract( IsOneWay=true )] void DoMath(MathRequest request); }
  31. 32. Service Contract: Duplex [ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(ICalculator Results ) ] public interface ICalculatorProblems { [OperationContract(IsOneWay=true)] void DoMath(MathRequest request); } public interface ICalculatorResults { [OperationContract(IsOneWay=true)] void DisplayResults(MathResponse response); }
  32. 33. Service Contract: Faults t ry { return n1 / n2; } catch (DivideByZeroException e) { MyMathFault f = new MyMathFault (n1, n2); FaultReason r = new FaultReason(&quot;Divide By Zero&quot;); throw new Fault Exception < MyMathFault >( f, r ); } [ServiceContract(Session=true)] public interface ICalculator { [OperationContract] [FaultContract(typeof( MyMathFault ))] int DoMath(int a, int b, string op); }
  33. 34. Service Contract: Versioning [ServiceContract] public interface ICalculator2 : ICalculator { [OperationContract(IsOneWay=true)] void SolveAndStoreProblem (ComplexProblem p); }
  34. 35. Service Contract: Streams [ServiceContract ] public interface IStreamCalculator { [OperationContract] Stream Fibonacci(int iterations); }
  35. 36. Data Contract [DataContract] public enum Position { [ EnumMember ] Employee, [ EnumMember ] Manager, [ EnumMember( Value = “ Vendor&quot; ) ] Contractor, NotASerializableEnumeration }
  36. 37. Data Contract: Names [DataContract( Name=“Complex”, Namespace=“http://BigMath.Samples” )] public class ComplexNumber { [DataMember( Name=“RealPart” )] public double Real = 0.0D; [DataMember( Name=“ImaginaryPart” )] public double Imaginary = 0.0D; public ComplexNumber(double r, double i) { this.Real = r; this.Imaginary = i; } }
  37. 38. Data Contract: Enumerations [DataContract] public enum Position { [EnumMember] Employee, [EnumMember] Manager, [EnumMember(Value = “Vendor&quot;)] Contractor, NotASerializableEnumeration }
  38. 39. Message Contract [MessageContract] public class ComplexProblem { [MessageHeader(Name=&quot;Op&quot;, MustUnderstand=true)] public string operation; [MessageBodyMember] public ComplexNumber n1; [MessageBodyMember] public ComplexNumber n2; [MessageBodyMember] public ComplexNumber solution; // Constructors… }
  39. 40. Mapping Contracts (1/2) [ MessageContract ] public class MyRequest { [MessageHeader] public int Amount; [MessageBody] public ItemInfo Info; } [ DataContract ] public class ItemInfo { [DataMember] public int ID; [DataMember] public double Cost; [DataMember] public string Name; } wsdl:message wsdl:part xsd:element
  40. 41. Mapping Contracts (2/2) [ ServiceContract ] public interface MyContract { [OperationContract] MyReply MyOp(MyRequest request); [OperationContract] void MyOp2(MyRequest2 request); } wsdl:portType wsdl:operation
  41. 42. Agenda <ul><li>Introduction </li></ul><ul><li>Overview </li></ul><ul><li>Contracts </li></ul><ul><li>Bindings </li></ul><ul><li>Behaviours </li></ul><ul><li>Summary </li></ul>
  42. 43. Bindings & Binding Elements Transport IPC MSMQ Custom TCP HTTP Protocol Encoders .NET TX Custom Security Reliability Binding HTTP TX Security Reliability Text Text Binary Custom TCP Binary
  43. 44. Binding Element Features <ul><li>Transport selection </li></ul><ul><ul><li>TCP, HTTP, Named Pipes, P2P, MSMQ, Custom </li></ul></ul><ul><ul><li>Transport level security, Streaming </li></ul></ul><ul><li>Encoding </li></ul><ul><ul><li>Text, Binary, MTOM, Custom </li></ul></ul><ul><li>End-to-end Security </li></ul><ul><ul><li>Confidentiality, integrity, authN, authZ, Federation </li></ul></ul><ul><ul><li>Credentials: X509, User/Pwd, Kerberos, SAML, InfoCard , Custom </li></ul></ul><ul><li>End-to-end Reliable messaging </li></ul><ul><ul><li>Transport independent QoS (in order, exactly once) </li></ul></ul><ul><ul><li>Volatile and durable queues </li></ul></ul><ul><li>Transactions </li></ul><ul><ul><li>Shared transactions for “synchronous” operations </li></ul></ul><ul><ul><li>Transactional queues for “asynchronous” operations </li></ul></ul><ul><li>[Your own feature goes here] </li></ul>
  44. 45. System-Provided Bindings N = None | T = Transport | M = Message | B = Both | RS = Reliable Sessions Binding Interop Security Session TX Duplex BasicHttpBinding BP 1.1 N, T N N n/a WSHttpBinding WS M , T, X N , T, RS N , Yes n/a WSDualHttpBinding WS M RS N , Yes Yes WSFederationBinding Federation M N , RS N , Yes No NetTcpBinding .NET T , M T ,RS N , Yes Yes NetNamedPipeBinding .NET T T , N N , Yes Yes NetPeerTcpBinding Peer T N N Yes NetMsmqBinding .NET T , M, X N N , Yes No MsmqIntegrationBinding MSMQ T N N , Yes n/a
  45. 46. Binding in Config <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?> <configuration> <system.serviceModel> <services> <service serviceType=&quot;CalculatorService&quot;> <endpoint address=&quot;Calculator&quot; bindingSectionName=&quot;basicProfileBinding&quot; contractType=&quot;ICalculator&quot; /> </service> </services> </system.serviceModel> </configuration>
  46. 47. Configuring Bindings <endpoint address=&quot;Calculator&quot; bindingSectionName=&quot; basic Http Binding &quot; bindingConfiguration=&quot; UsernameBinding &quot; contractType=&quot;ICalculator&quot; /> <bindings> <basicHttpBinding> <binding name=&quot; UsernameBinding &quot; messageEncoding=&quot;Mtom&quot;> <security mode=&quot;Message&quot;> <message clientCredentialType=&quot;UserName&quot;/> </security> </binding> </basicHttpBinding> < /bindings>
  47. 48. Custom Bindings <bindings> <customBinding> <customBinding> <binding name=&quot;ReliableTCP&quot;> <reliableSession inactivityTimeout=&quot;0:0:5“ ordered=&quot;true&quot;/> <binaryMessageEncoding/> <tcpTransport transferMode=&quot;Buffered&quot;/> </binding> </customBinding> </customBinding> </bindings>
  48. 49. Choosing Bindings Any Protocol Any Binding Any Binding WCF WCF MSMQ WCF COM+/ES WCF MSMQ Protocol WS-* Protocols MSMQ Binding Moniker ASMX/WSE3 WCF WS-* Protocols Http/WS Binding Other Platform WCF WS-* Protocols Http/WS Binding
  49. 50. Interaction of Bindings and Code <ul><li>Bindings provide features that affect code </li></ul><ul><ul><li>Session </li></ul></ul><ul><ul><li>Duplex </li></ul></ul><ul><ul><li>Ordered Delivery </li></ul></ul><ul><ul><li>Transaction Flow </li></ul></ul><ul><ul><li>Queued Delivery </li></ul></ul><ul><li>Attribute capture the code’s requirements </li></ul><ul><li>Infrastructure ensures that all the bindings satisfy these requirements </li></ul>
  50. 51. Agenda <ul><li>Introduction </li></ul><ul><li>Overview </li></ul><ul><li>Contracts </li></ul><ul><li>Bindings </li></ul><ul><li>Behaviours </li></ul><ul><li>Summary </li></ul>
  51. 52. Behaviors Client-Side Behaviors Service-Side Behaviors Service Caller Be Be C B A C B A A B C C B A
  52. 53. Behaviors: Overview <ul><li>Behaviors are all local </li></ul><ul><li>Developers care about some behaviors </li></ul><ul><ul><li>Concurrency, instancing model, … </li></ul></ul><ul><ul><li>Everything that affects the correctness of the service </li></ul></ul><ul><li>Deployers care about other behaviors </li></ul><ul><ul><li>Throttling, Metadata exposure, message routing info, … </li></ul></ul><ul><ul><li>Everything that has to do with the service’s runtime aspects </li></ul></ul><ul><li>Anything you can do in config, you can do in code </li></ul><ul><ul><li>Code is King – you can always override the config settings </li></ul></ul>
  53. 54. Example: Security Service Client Be Be Bindings Move Claims in Messages Behaviors Implement Security Gates Behaviors Provide Credentials C B A C B A A B C C B A
  54. 55. Example: Transactions Service Caller Be Bindings Flow Transactions Behaviors AutoEnlist and AutoComplete C B A C B A A B C C B A
  55. 56. Anti-Example: Reliable Sessions Service Caller Bindings provide Session and Guarantees C B A C B A A B C C B A
  56. 57. Behavior Features <ul><li>Operation timeouts (close, open, idle) </li></ul><ul><li>Concurrency, Instancing, Thread-Binding </li></ul><ul><li>Throttling </li></ul><ul><li>Faults, Exceptions </li></ul><ul><li>Impersonation, Authorization, Auditing </li></ul><ul><li>AutoEnlist, AutoComplete, Timeout, Isolation </li></ul><ul><li>Serialization, MustUnderstand </li></ul><ul><li>Metadata </li></ul><ul><li>More… </li></ul>
  57. 58. Features Summary Address Binding Behavior Contract HTTP Transport TCP Transport NamedPipe Transport MSMQ Transport Custom Transport WS-Security Protocol WS-RM Protocol WS-AT Protocol Duplex Channel Custom Protocol http://... net.tcp://... net.pipe://... net.msmq://... xxx://... Throttling Behavior Metadata Behavior Error Behavior Custom Behavior Instancing Behavior Concurrency Behavior Transaction Behavior Security Behavior Request/ Response One-Way Duplex net.p2p://... Peer Transport Externally visible, per-endpoint Opaque, per-service, endpoint, or op
  58. 59. WCF Application “Architecture” Channels Transport Channels (IPC, HTTP, TCP…) Reliability Message Encoder Security Hosting Environments WAS IIS .exe Windows Service DllHost Messaging Services Queuing Routing Eventing Discovery Service Model Application Instance Manager Context Manager Type Integration Service Methods Declarative Behaviors Transacted Methods
  59. 60. Presentation Takeaways <ul><li>WCF is the future of distributed computing </li></ul><ul><li>It combines the best of all existing Microsoft distributed computing stacks </li></ul><ul><li>It uses WS-* standards for interoperability and .NET value-add for performance and integration with existing solutions </li></ul><ul><li>WCF is available for Windows Vista, Windows XP SP2, Windows Server 2003 </li></ul><ul><li>Download WCF Today! </li></ul><ul><ul><li> </li></ul></ul><ul><li>Presentation code at </li></ul>