brian noyes chief architect idesign inc () session code: soa 305
TRANSCRIPT
![Page 1: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/1.jpg)
![Page 2: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/2.jpg)
Exercise WCF Best Practices
Brian NoyesChief ArchitectIDesign Inc (www.idesign.net) Session Code: SOA 305
![Page 3: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/3.jpg)
Chief ArchitectIDesign Inc. (www.idesign.net)
Microsoft Regional DirectorMVP
Microsoft MVPConnected Systems
About Brian Publishing
Developing Applications with Windows Workflow Foundation, LiveLessons training DVD, June 2007
Smart Client Deployment with ClickOnce, Addison Wesley, January 2007
Data Binding in Windows Forms 2.0, Addison Wesley, January 2006
MSDN Magazine, MSDN Online, CoDe Magazine, The Server Side .NET, asp.netPRO, Visual Studio Magazine
Speaking
Microsoft TechEd US, Europe, Malaysia, Visual Studio Connections, DevTeach, INETA Speakers Bureau, MSDN Webcasts
E-mail: [email protected]
Blog: http://briannoyes.net
![Page 4: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/4.jpg)
Agenda
Service Best Practices
Client Best Practices
Data Contracts
SOAP vs REST
![Page 5: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/5.jpg)
Service Definition
Separate contract from implementationContract (interface) first
Define services in a class library, not directly in a host projectLayering
Separate Service Layer?Instance model
Change to Per Call as defaultSession / Singleton when?
![Page 6: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/6.jpg)
Instance ModelBrian NoyesChief ArchitectIDesign Inc
demo
![Page 7: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/7.jpg)
Service Exception Handling
For operation specific exceptionsTry/catch, throw FaultException<T>
Favor using FaultException<T>FaultException can be ambiguous to the client because unhandled exceptions arrive as a FaultException
Include FaultContract in service contract definition if you throw FaultExceptions
Part of the API you are exposingFor global exception handling from services
Use an error handlerInclude exception details in debug builds only
![Page 8: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/8.jpg)
ExceptionsBrian NoyesChief ArchitectIDesign Inc
demo
![Page 9: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/9.jpg)
Service Security
Intranet servicesDefault Windows Auth may be all you needPossibly Hybrid – Windows Creds / Custom Application Roles
Extranet / Internet / Custom security needsUse ASP.NET Membership / Role providers
ASP.NET providersReally a standard .NET framework security infrastructureBuilt in providers for Windows or SQL Server – based credentials / rolesEasy to implement custom providersEstablish principal on the threadRe-usable across ASP.NET, WCF, WPF & Windows Forms (via Client Application Services)
![Page 10: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/10.jpg)
SecurityBrian NoyesChief ArchitectIDesign Inc
demo
![Page 11: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/11.jpg)
Service Hosting
Favor WAS Hosting when Server 2008 is an optionMultiple protocol supportIIS Hosting model and tools
Favor IIS for external HTTP only servicesBetter on-box scalability / availability through worker process modelBetter management tools
Favor self-hosting for stateful services, callbacks, .NET Service Bus, debuggingHave a console-based debug self-host for development time
Can be a Windows Service project that is used for production self-hosting with a mode switch for debugging
Consider Dublin hosting in the future
![Page 12: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/12.jpg)
Self Host Code
Do not put ServiceHost in a using statementDispose can throw an exception that masks the real exception thrown from Open callExplicitly call Close in try/catch, log/ deal with exception in catch
![Page 13: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/13.jpg)
Self-HostBrian NoyesChief ArchitectIDesign Inc
demo
![Page 14: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/14.jpg)
Agenda
Service Best Practices
Client Best Practices
Data Contracts
SOAP vs REST
![Page 15: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/15.jpg)
Client Proxy Classes
Favor static proxy class over ChannelFactoryConnection caching in the base class in 3.5Place for encapsulation of common patterns
Hand-code or micro-code generate proxy classes for internal services
Less bloated codeShare service contract and data contracts through librariesExplicit control over config file
![Page 16: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/16.jpg)
Client ProxiesBrian NoyesChief ArchitectIDesign Inc
demo
![Page 17: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/17.jpg)
Client Proxy Classes
Add Service Reference for external services or when you want an async API on the client
Clean up config after it destroys itMake sure to add references to data contract libraries before adding the service reference to avoid duplicate definitionsLive with the duplicate service contract definition instead of needing to repeatedly clean up the proxy code
![Page 18: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/18.jpg)
Add Service ReferenceBrian NoyesChief ArchitectIDesign Inc
demo
![Page 19: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/19.jpg)
Client Proxy Management
Cache client proxies if frequent calls to avoid session establishment cost
If secure / reliable session enabledHave to deal more cautiously with faulted proxies
Check proxy state before usingGet rid of proxy after exception
Don’t put proxies in a using statementDispose call might throw exception and mask real exceptionExplicitly close in a try/catch block, and if Close throws an exception, Abort the proxy to ensure resource clean up
![Page 20: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/20.jpg)
Proxy CachingBrian NoyesChief ArchitectIDesign Inc
demo
![Page 21: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/21.jpg)
Client Exception Management
All exceptions thrown from a service call derive from CommunicationExceptionFaultException could be wrapped unhandled exception on the client, or explicit error returned from the serviceFaultException<T> always an explicit error returned from the serviceSimple approach:
Any exception from a proxy call, safe close the proxyAdvanced approach:
FaultException<T> - proxy is reusable
![Page 22: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/22.jpg)
Client ExceptionsBrian NoyesChief ArchitectIDesign Inc
demo
![Page 23: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/23.jpg)
Agenda
Service Best Practices
Client Best Practices
Data Contracts
SOAP vs REST
![Page 24: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/24.jpg)
Data Contracts
Favor data contracts over serializable typesMore explicit model, better control over what the client sees
Implement IExtensibleDataObjectAvoids dropping data that the service / client does not understand
Avoid passing complex .NET specific types for interoperable services
DataSets and Exception types
![Page 25: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/25.jpg)
Data Contracts
Avoid XmlSerializer and MessageContracts except for interoperable scenarios and REST services
![Page 26: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/26.jpg)
Data ContractsBrian NoyesChief ArchitectIDesign Inc
demo
![Page 27: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/27.jpg)
Agenda
Service Best Practices
Client Best Practices
Data Contracts
SOAP vs REST
![Page 28: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/28.jpg)
SOAP vs REST
Favor SOAP services when you are writing a service that only your code will consumeFavor REST services for publicly exposed, data oriented services
![Page 29: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/29.jpg)
ResourcesIDesign WCF Master Class
IDesign WCF Coding Standard – http://www.idesign.net
Programming WCF, Juval Lowy, O’Reilly & Associates, 2007
Learning WCF, Michele Leroux Bustamante, O’Reilly & Associates, 2007
Connect Apps with WCF, Brian Noyes, Visual Studio Magazine, Feb 2008, http://visualstudiomagazine.com/articles/2008/02/01/connect-apps-with-wcf.aspx?sc_lang=en
Wenlong Dong’s Blog: http://blogs.msdn.com/wenlong/default.aspx
E-mail: [email protected]: http://briannoyes.net
![Page 30: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/30.jpg)
question & answer
![Page 31: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/31.jpg)
Complete a session evaluation and enter to win!
10 pairs of MP3 sunglasses to be won
![Page 32: Brian Noyes Chief Architect IDesign Inc () Session Code: SOA 305](https://reader036.vdocuments.site/reader036/viewer/2022081519/56649e6c5503460f94b6b89a/html5/thumbnails/32.jpg)
© 2009 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.