Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Deep Dive into Best Practices with the Windows Communication Foundation John Justice COM415 Program Manager Microsoft Corporation.

Similar presentations


Presentation on theme: "A Deep Dive into Best Practices with the Windows Communication Foundation John Justice COM415 Program Manager Microsoft Corporation."— Presentation transcript:

1 A Deep Dive into Best Practices with the Windows Communication Foundation John Justice COM415 Program Manager Microsoft Corporation

2 What we’re covering today: 10 – Choose a Binding that Fits Your Needs 6 – Stay Flexible with Config 6 – Stay Flexible with Config 5 – Send Faults, not Exceptions 5 – Send Faults, not Exceptions 4 – Avoid UI Threading Conflicts 4 – Avoid UI Threading Conflicts 3 – Use UDDI Internally 3 – Use UDDI Internally 2 – Go Beyond XML Interoperability 2 – Go Beyond XML Interoperability 1 – Understand the Service Lifecycle 1 – Understand the Service Lifecycle

3 10: Choose a Binding that Fits Your Needs

4 BasicHttpBindingWsHttpBindingWsDualHttpBinding Bindings: Out of the Box NetTcpBindingNetNamedPipeBindingNetMsmqBindingNetPeerTcpBinding Interoperable WCF to WCF

5 Bindings: Decision Tree BasicHttpBinding WsHttpBinding Interop? What Level? Duplex? WSDualHttpBinding NetNamedPipeBinding NetMsmqBinding NetPeerTcpBinding NetTcpBinding No Basi c No Yes Local? Need Queues? Peer to Peer? No No No Yes Yes Yes WS Yes

6 Bindings

7 6: Stay Flexible with Config

8 Config: Range of options Deployment Flexibility All Code All Config End-user apps Enterprise apps

9 Config: When you need to lock down… Lock down only what you must Check your requirements Make sure your checks are being executed Write a custom ValidatorWrite a custom Validator Create your own BindingCreate your own Binding Require your Validator with in machine.configRequire your Validator with in machine.config Use a custom ServiceHostUse a custom ServiceHost Note: A malicious programmer can circumvent any of these options in code.

10 Stay Flexible with Config

11 5: Send Faults, not Exceptions

12 Send Faults, Not Exceptions Faults are at the contract level Don’t shove implementation level exceptions into your Faults When you get into trouble, send business level faults, not exceptions Indigo makes defining and sending custom faults easy

13 Custom Faults

14 4: Avoid UI Threading Conflicts

15 Avoid UI Threading Conflicts Windows Forms and Windows Presentation Foundation apps use the main program thread for updates WCF services use the main program thread for processing requests If you host a WCF service (or duplex client) in a Windows Forms or WPF app, you’ll need to be careful

16 Windows Forms Threading

17 3: Use UDDI Internally

18 Use UDDI Internally UDDI isn’t just for public registries When you need a layer of Web service indirection, think UDDI Development -> Test -> Staging -> Production Choosing between non-clustered services

19 UDDI

20 2: Go beyond XML Interoperability

21 Interop: Send Useful XML Infrastructure interoperability: == The plumbing can deliver your XML Being kind to your consumers: == There’s a good programming experience on both sides of the wire Use a practical, platform neutral subset of XML Schema Follow solid engineering practices when designing your contracts

22 Interop: Contract Guidelines Use our work: prototype with DataContract Use simple types that map well between.NET and Java DataSet is great for.NET to.NET, but isn’t supported well by other vendors Use typed, self-contained complex types When writing XSD-first: Avoid Avoid

23 1: Understand the Service Lifecycle

24 Service Lifecycle: Primary players Channel Lives for lifetime of channel sessionLives for lifetime of channel session Holds security informationHolds security information Holds Reliable Session IDHolds Reliable Session ID InstanceContext Provides connection between Channel and Service objectProvides connection between Channel and Service object Controls instance sharing and lifetimeControls instance sharing and lifetime Service Your object that implements the contractYour object that implements the contract

25 Service Lifecycle: Channel session Channel Lifetime: Lives for the duration of the channel sessionLifetime: Lives for the duration of the channel session Channel lifetime varies by transportChannel lifetime varies by transport InstanceContextService What’s the session lifetime of my channel? HTTP  One Operation TCP  Connection MSMQ  One Operation Turn on Reliable Sessions to extend the session lifetime

26 Service Lifecycle: Channel session Channel Turn on Reliable Sessions to extend the session lifetime InstanceContextService </binding> </bindings>

27 Service Lifecycle: Channel session Channel Get finer-grained control with IsInitiating() and IsTerminating InstanceContextService // Close the Channel after calling [OperationContract(IsTerminating=true)] public String Echo(String input);

28 Service Lifecycle: Instancing Channel Q: How is my InstanceContext related to my Channel? A: InstanceMode InstanceContextService Provides connection between Channel and Service objectProvides connection between Channel and Service object Controls instance sharing and lifetimeControls instance sharing and lifetime

29 Service Lifecycle: Instancing ChannelInstanceContextService Instance Modes: PerCall (Default)PerCall (Default) PrivateSessionPrivateSession SharedSessionSharedSession SingletonSingleton ServiceBehavior(InstanceMode=Ins tanceMode.PerSession)] public class MyService : IMyService {…}

30 Service Lifecycle Instancing decision tree NeedState? Use Per Call – New context every call Use Singleton – One context for everyone Use Shared Session – Same as private session, but can share contexts within a group Use Private Session – One context per client StateScope? Shared? Yes Yes Grouped No No Global

31 Service Lifecycle: Service type ChannelInstanceContextService [OperationBehavior( ReleaseInstance=ReleaseInstance Mode.BeforeAndAfterCall)] public String Echo(String input) {…} By default, Service type lifetime is connected to InstanceContext Override this connection with ReleaseInstanceOverride this connection with ReleaseInstance BeforeCallBeforeCall AfterCallAfterCall BeforeAndAfterCal lBeforeAndAfterCal l

32 Community Resources At PDC For more information, go see COM423: WCF: Web Services Interoperability with Java/J2EE (Thurs 2:15pm) COM424: WCF: Extending the Channel Layer (Thurs 3:45pm) COM326: WCF: Web Services for XML Programmers (Thurs: 5:15pm) COM429: WCF: Extending the Service Model Layer (Fri: 10:30pm) Labs: COMHOL22, COMHOL28, COMHOL29 Ask The Experts table: General WCF (Thursday night) COM Track lounge After PDC If you missed this related session, watch it on the DVD COM416: WCF: Under the Hood of the WCF Channel Layer COM417: WCF: Under the Hood of the Service Model Layer MSDN dev center: http://msdn.microsoft.com/webservices/ Channel 9 tag: http://channel9.msdn.com/tags/Indigo

33 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.


Download ppt "A Deep Dive into Best Practices with the Windows Communication Foundation John Justice COM415 Program Manager Microsoft Corporation."

Similar presentations


Ads by Google