introduction to Windows Comunication Foundation

  • 3,190 views
Uploaded on

A good slide to to start working in WCF

A good slide to to start working in WCF

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • I can not download this slide from the linkage provided by the slideshare.net. can you please tell me why?
    thanks.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,190
On Slideshare
0
From Embeds
0
Number of Embeds
7

Actions

Shares
Downloads
437
Comments
1
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.  
  • 2. The Windows Communication Foundation
  • 3.
    • Interoperability & Integration
    • Secure, Reliable, Transacted Messaging
    • Decoupled, Dynamic Applications
    The Connectivity Imperative
  • 4. .NET At The Core
  • 5. Windows Communication Foundation The Unified Framework For Rapidly Building Service-Oriented Applications
  • 6. Windows Communication Foundation INTEROPERABILITY PRODUCTIVITY SERVICE-ORIENTED DEVELOPMENT
    • Broad Support for WS-* specifications
    • Compatible with existing MS distributed application technologies
    • Unifies today’s distributed technologies
    • Attribute-based development
    • Visual Studio 2005 integration
    • Enables development of loosely-coupled services
    • Config-based communication
  • 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
  • 8. WS-* Protocol Support XML Messaging Security Transactions Reliable Messaging Metadata
  • 9. Investment Protection SIDE-BY-SIDE Interop UPGRADE
  • 10. SERVICE ORIENTATION
  • 11. From Objects to Services
    • Polymorphism
    • Encapsulation
    • Subclassing
    • Message-based
    • Schema+Contract+Policy
    • Broad Interop
    • Location Transparent
    • Tight Coupling
    • Runtime Metadata
    Object-Oriented Service-Oriented Component-Oriented 1980s 2000s 1990s
  • 12. Four Tenets of Service Orientation SERVICE ORIENTATION Compatibility Based On Policy Share Schema & Contract, Not Class Services Are Autonomous Boundaries Are Explicit
  • 13. Conventional Web Services
      • The old way of easily exposing components (ASMX):
    .NET Component ASMX Web Service HTTP Client
  • 14. WCF Services
      • The new way of easily exposing components (WCF):
    .NET Component HTTP Host TCP Host ICP Host MSMQ Host HTTP Client TCP Client ICP Client MSMQ Client Service Contract
  • 15. The Windows Communication Foundation
  • 16. Main Design Goal
    • Unification
      • Unify today’s distributed technology stacks
      • Talk on-machine, cross-machine, cross-networks & Internet
    • Productivity
      • Codify best practices for building distributed apps
      • Maximize productivity
    • Integration
      • Interoperate with apps running on other platforms
      • Integrate with Microsoft’s existing technologies
  • 17. Agenda
    • Introduction
    • Overview
      • Main Concepts
      • Hello World
    • Contracts
    • Bindings
    • Behaviours
    • Summary
  • 18. Callers and Services Caller Service
  • 19. Endpoints Caller Service Endpoint Endpoint Endpoint Endpoint
  • 20. Address, Binding, Contract Service Caller C B A C B A A B C Address Where? Contract What? Binding How? C B A
  • 21. Creating Endpoints Service Service Host Caller Proxy or ChannelFactory A B C C B A C B A C B A
  • 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
  • 23. Hello World
  • 24. Agenda
    • Introduction
    • Overview
    • Contracts
      • Service
      • Data
      • Message
    • Bindings
    • Behaviours
      • Instancing
    • Summary
  • 25. WCF Contracts Overview
    • Service Contracts
      • Describe the operations a service can perform
      • Map CLR types to WSDL
    • Data Contracts
      • Describes a data structure
      • Maps CLR types to XSD
    • Message Contracts
      • Defines the structure of the message on the wire
      • Maps CLR types to SOAP messages
  • 26. Service Contract [ServiceContract] public interface ICalculator { [OperationContract] int DoMath(int a, int b, string op); }
  • 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); }
  • 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)
  • 29. Service Contract: Names [ServiceContract( Namespace ="http://TechEd.WCF.Intro")] public interface IGreetings { [OperationContract( Name =“SayHello", Action ="http://TechEd.WCF.Intro/HelloRequest", ReplyAction ="http://TechEd.WCF.Intro/HelloResponse")] string Greet(string name); [OperationContractAttribute( Action = "*" )] void UnrecognizedMessageHandler( Message msg ); } class GreetingService : IGreetings { public string Greet(string name) { return “Hello, " + name; } public void UnrecognizedMessageHandler(Message msg) { Console.WriteLine("Unrecognized message: " + msg.ToString()); } }
  • 30. Modeling Request/Reply Operations
    • On the wire everything is asynchronous
    • Therefore, Request and Reply correlation can be modeled in 2 ways
    • It can be modeled either as a synchronous (blocking) method call
    • or using the .NET Async-Pattern
    • The implementation on the client and the service can be different !
    [OperationContract] MathResponse DoMsgMath(MathRequest msg); [OperationContrac t(AsyncPattern=true) ] IAsyncResult BeginDoMsgMath(MathRequest msg, AsyncCallback cb, object state ) ; MathResponse EndDoMsgMath(IAsyncResult call);
  • 31. Service Contract: OneWay [ServiceContract] public interface IOneWayCalculator { [OperationContract( IsOneWay=true )] void DoMath(MathRequest request); }
  • 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); }
  • 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); }
  • 34. Service Contract: Versioning [ServiceContract] public interface ICalculator2 : ICalculator { [OperationContract(IsOneWay=true)] void SolveAndStoreProblem (ComplexProblem p); }
  • 35. Service Contract: Streams [ServiceContract ] public interface IStreamCalculator { [OperationContract] Stream Fibonacci(int iterations); }
  • 36. Data Contract [DataContract] public enum Position { [ EnumMember ] Employee, [ EnumMember ] Manager, [ EnumMember( Value = “ Vendor&quot; ) ] Contractor, NotASerializableEnumeration }
  • 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; } }
  • 38. Data Contract: Enumerations [DataContract] public enum Position { [EnumMember] Employee, [EnumMember] Manager, [EnumMember(Value = “Vendor&quot;)] Contractor, NotASerializableEnumeration }
  • 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… }
  • 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
  • 41. Mapping Contracts (2/2) [ ServiceContract ] public interface MyContract { [OperationContract] MyReply MyOp(MyRequest request); [OperationContract] void MyOp2(MyRequest2 request); } wsdl:portType wsdl:operation
  • 42. Agenda
    • Introduction
    • Overview
    • Contracts
    • Bindings
    • Behaviours
    • Summary
  • 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
  • 44. Binding Element Features
    • Transport selection
      • TCP, HTTP, Named Pipes, P2P, MSMQ, Custom
      • Transport level security, Streaming
    • Encoding
      • Text, Binary, MTOM, Custom
    • End-to-end Security
      • Confidentiality, integrity, authN, authZ, Federation
      • Credentials: X509, User/Pwd, Kerberos, SAML, InfoCard , Custom
    • End-to-end Reliable messaging
      • Transport independent QoS (in order, exactly once)
      • Volatile and durable queues
    • Transactions
      • Shared transactions for “synchronous” operations
      • Transactional queues for “asynchronous” operations
    • [Your own feature goes here]
  • 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
  • 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>
  • 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>
  • 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>
  • 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
  • 50. Interaction of Bindings and Code
    • Bindings provide features that affect code
      • Session
      • Duplex
      • Ordered Delivery
      • Transaction Flow
      • Queued Delivery
    • Attribute capture the code’s requirements
    • Infrastructure ensures that all the bindings satisfy these requirements
  • 51. Agenda
    • Introduction
    • Overview
    • Contracts
    • Bindings
    • Behaviours
    • Summary
  • 52. Behaviors Client-Side Behaviors Service-Side Behaviors Service Caller Be Be C B A C B A A B C C B A
  • 53. Behaviors: Overview
    • Behaviors are all local
    • Developers care about some behaviors
      • Concurrency, instancing model, …
      • Everything that affects the correctness of the service
    • Deployers care about other behaviors
      • Throttling, Metadata exposure, message routing info, …
      • Everything that has to do with the service’s runtime aspects
    • Anything you can do in config, you can do in code
      • Code is King – you can always override the config settings
  • 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
  • 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
  • 56. Anti-Example: Reliable Sessions Service Caller Bindings provide Session and Guarantees C B A C B A A B C C B A
  • 57. Behavior Features
    • Operation timeouts (close, open, idle)
    • Concurrency, Instancing, Thread-Binding
    • Throttling
    • Faults, Exceptions
    • Impersonation, Authorization, Auditing
    • AutoEnlist, AutoComplete, Timeout, Isolation
    • Serialization, MustUnderstand
    • Metadata
    • More…
  • 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
  • 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
  • 60. Presentation Takeaways
    • WCF is the future of distributed computing
    • It combines the best of all existing Microsoft distributed computing stacks
    • It uses WS-* standards for interoperability and .NET value-add for performance and integration with existing solutions
    • WCF is available for Windows Vista, Windows XP SP2, Windows Server 2003
    • Download WCF Today!
      • http://www.NetFx3.com/
    • Presentation code at ShyCohen.com
  • 61.