SlideShare a Scribd company logo
1 of 20
28 July, 2011 Windows Communication Foundation (WCF) Best Practices
Don't build a WCF service ! Unless you have a good reason for it: Security reasons (business Logic in perimeter network) Shared business logic (multiple apps or non .NET apps) Heavy resource consumption (long-running?) Separate maintainable Separate scalable 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  2
Know the tools! Svcutil.exe SvcConfigEditor.exe  SvcTraceViewer.exe  REST starter kit AppFabric Web Services Software Factory (WSSF)   http://servicefactory.codeplex.com/ Enterprise Library (EntLib) Exception Handling Application Block Logging Application Block Validation Application Block 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  3
Additional tools on CodePlex http://wcfloadtest.codeplex.com takes a WCF trace file and a WCF client proxy, or a WCF interface contract, and generates a C# unit test that replays the same sequence of calls found in the trace file. The unit test can then be used to load-test the target  http://wcfcontrib.codeplex.com/ library with infrastructure implementations for client and service communications http://wcfsecurity.codeplex.com/ http://wcfextensions.codeplex.com/ WCF Compression Channel 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  4
Service best practices Separate contract from implementation Contract (interface) first (http://wscfblue.codeplex.com/) Define services in a class library, not directly in a host project Layering Separate Service Layer Instance model Change to Per Call as default Session / Singleton – use only when needed 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  5
Exception Handling (I) For operation specific exceptions Try/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 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  6
Exception Handling (II) If you throw FaultExceptions Part of the API you are exposing For global exception handling from services Use an error handler Include exception details in debug builds only !! 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  7
Hosting Favor WAS Hosting when on Windows Server 2008 Multiple protocol support IIS Hosting model and tools Use IIS hosting for external HTTP only Favor self-hosting for stateful services, callbacks, .NET Service Bus, debugging Have 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 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  8
When you self host … 		 Do not put ServiceHost in a using statement in production code Dispose can throw an exception that masks the real exception thrown from Open call Explicitly call Close in try/catch and log/ deal with exception in catch 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  9
Client Proxy Classes (I) Use static proxy class when possible instead of ChannelFactory Connection caching in the base class in 3.5 Place for encapsulation of common patterns Hand-code or generate proxy classes for internal services Less bloated code Share service contract and data contracts through libraries Explicit control over config file 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  10
Client Proxy Classes (II) Add Service Reference for external services or when you want an async API on the client Clean up config after it messes it up Make sure to add references to data contract libraries before adding the service reference to avoid duplicate definitions Live with the duplicate service contract definition instead of needing to repeatedly clean up the proxy code 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  11
Client Proxy Management Cache client proxies if frequent calls to avoid session establishment cost If secure / reliable session enabled Have to deal more cautiously with faulted proxies Check proxy state before using Get rid of proxy after exception Don’t put proxies in a using statement Dispose call might throw exception and mask real exception Explicitly close in a try/catch block, and if Close throws an exception, Abort the proxy to ensure resource clean up 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  12
Client Exception Management All exceptions thrown from a service call derive from CommunicationException FaultException<T> always an explicit error returned from the service Simple approach: Any exception from a proxy call, safe close the proxy Advanced approach: FaultException<T> - proxy is reusable 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  13
Data Contracts Avoid XmlSerializer and MessageContracts except for interoperable scenarios and REST services Favor data contracts over serializable types More explicit model, better control over what the client sees Implement IExtensibleDataObject Avoids dropping data that the service / client does not understand Avoid passing complex .NET specific types for interoperable services DataSets and Exception types 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  14
SOAP vs REST Favor SOAP services when you are writing a service that only your code will consume Favor REST services for publicly exposed, data oriented services 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  15
Don't forget XmlNamespace settings By default WCF puts the “http://tempuri.org/”  namespace in your wsdl and contracts. Normally you don’t want this. You can control this from three places: In your config file in the services/service/endpoint/bindingNamespaceattribute In your servicecontract: [ServiceContract(Namespace="http://myuri.net/")]   In your servicebehavior: [ServiceBehavior(Namespace="http://myuri.net/")] 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  16
More subtle things with WCF	 One-way !? One-way is not always really one-way even when doing oneway, closing a client can block until the service side is done this is happening in quite some cases where bindings are configured to maintain sessions.  it happens for example with Message security and or reliable session support (WS-ReliableMessaging). 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  17
The limits of reliable Messaging with WCF (I) Messages still can get lost with this mechanism if for example  the service is shutdown  IIS reset If you need end-to-end durable reliable messaging with full support for transactional I/O you need an infrastructure that's in control of both ends of the communication  NetMsmqBinding.  MSMQ messages are limited to 4 MB 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  18
The limits of reliable Messaging with WCF (II) If you are mostly worried about not losing messages under less-than-optimal networking conditions or require session support the reliable session support in WCF is the right choice isn’t very handy with load balancers Sticky session/session affinity 28 July, 2011 Windows Communication Foundation (WCF) Best Practices  19
20 Windows Communication Foundation (WCF) Best Practices  28 July, 2011

More Related Content

What's hot

WCF tutorial
WCF tutorialWCF tutorial
WCF tutorialAbhi Arya
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Saltmarch Media
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf serviceBinu Bhasuran
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)ipower softwares
 
REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5Rob Windsor
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsPeter Gfader
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCFybbest
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationredaxe12
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIKevin Hazzard
 
Advanced WCF Workshop
Advanced WCF WorkshopAdvanced WCF Workshop
Advanced WCF WorkshopIdo Flatow
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonAdnan Masood
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio
 

What's hot (20)

Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0
 
WCF
WCFWCF
WCF
 
Wcf
WcfWcf
Wcf
 
WCF for begineers
WCF  for begineersWCF  for begineers
WCF for begineers
 
WCF And ASMX Web Services
WCF And ASMX Web ServicesWCF And ASMX Web Services
WCF And ASMX Web Services
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)
 
Wcf development
Wcf developmentWcf development
Wcf development
 
REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
 
WCF Introduction
WCF IntroductionWCF Introduction
WCF Introduction
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCF
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundation
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
Advanced WCF Workshop
Advanced WCF WorkshopAdvanced WCF Workshop
Advanced WCF Workshop
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
 

Viewers also liked

Wcf hosting and endpoints
Wcf hosting and endpointsWcf hosting and endpoints
Wcf hosting and endpointsdilipkumardubey
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practiceYu GUAN
 
Windows service best practice
Windows service best practiceWindows service best practice
Windows service best practiceYu GUAN
 
Project Management with SharePoint 2010
Project Management with SharePoint 2010Project Management with SharePoint 2010
Project Management with SharePoint 2010Greg Kiefer
 
WCF for Dummies (Parte II)
WCF for Dummies (Parte II)WCF for Dummies (Parte II)
WCF for Dummies (Parte II)Will.i.am
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIEyal Vardi
 
The Dark Side of Microservices
The Dark Side of MicroservicesThe Dark Side of Microservices
The Dark Side of MicroservicesNicolas Fränkel
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
Microservices architecture overview v2
Microservices architecture overview v2Microservices architecture overview v2
Microservices architecture overview v2Dmitry Skaredov
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State TransferPeter R. Egli
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsIdo Flatow
 
API 101 - Understanding APIs.
API 101 - Understanding APIs.API 101 - Understanding APIs.
API 101 - Understanding APIs.Kirsten Hunter
 

Viewers also liked (17)

Wcf hosting and endpoints
Wcf hosting and endpointsWcf hosting and endpoints
Wcf hosting and endpoints
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practice
 
Windows service best practice
Windows service best practiceWindows service best practice
Windows service best practice
 
Making WCF Simple
Making WCF SimpleMaking WCF Simple
Making WCF Simple
 
Project Management with SharePoint 2010
Project Management with SharePoint 2010Project Management with SharePoint 2010
Project Management with SharePoint 2010
 
WFC #1
WFC #1WFC #1
WFC #1
 
WCF for Dummies (Parte II)
WCF for Dummies (Parte II)WCF for Dummies (Parte II)
WCF for Dummies (Parte II)
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
The Dark Side of Microservices
The Dark Side of MicroservicesThe Dark Side of Microservices
The Dark Side of Microservices
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Microservices architecture overview v2
Microservices architecture overview v2Microservices architecture overview v2
Microservices architecture overview v2
 
Api types
Api typesApi types
Api types
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 
Api for dummies
Api for dummies  Api for dummies
Api for dummies
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
API 101 - Understanding APIs.
API 101 - Understanding APIs.API 101 - Understanding APIs.
API 101 - Understanding APIs.
 

Similar to Windows Communication Foundation (WCF) Best Practices

Wcf best practices
Wcf best practicesWcf best practices
Wcf best practicesbrijesh pal
 
Take Your Web Development To The Next Level With These Top 2 Libraries
Take Your Web Development To The Next Level With These Top 2 LibrariesTake Your Web Development To The Next Level With These Top 2 Libraries
Take Your Web Development To The Next Level With These Top 2 LibrariesPolyxer Systems
 
Enterprise Library 2.0
Enterprise Library 2.0Enterprise Library 2.0
Enterprise Library 2.0Raju Permandla
 
"Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment""Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment"webhostingguy
 
Stateful mock servers to the rescue on REST ecosystems
Stateful mock servers to the rescue on REST ecosystemsStateful mock servers to the rescue on REST ecosystems
Stateful mock servers to the rescue on REST ecosystemsNuno Caneco
 
Dynamic and modular Web Applications with Equinox and Vaadin
Dynamic and modular Web Applications with Equinox and VaadinDynamic and modular Web Applications with Equinox and Vaadin
Dynamic and modular Web Applications with Equinox and VaadinKai Tödter
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Steven Smith
 
MSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF DemystifiedMSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF DemystifiedDave Bost
 
WINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONWINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONDeepika Chaudhary
 
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS SitesAutomated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sitesjoelabrahamsson
 
.NET Intro & Dependency Injection Workshop
.NET Intro & Dependency Injection Workshop.NET Intro & Dependency Injection Workshop
.NET Intro & Dependency Injection WorkshopSerhii Kokhan
 
Jeffrey Richter
Jeffrey RichterJeffrey Richter
Jeffrey RichterCodeFest
 
Debugging java deployments_2
Debugging java deployments_2Debugging java deployments_2
Debugging java deployments_2Rohit Kelapure
 
Dev212 Comparing Net And Java The View From 2006
Dev212 Comparing  Net And Java  The View From 2006Dev212 Comparing  Net And Java  The View From 2006
Dev212 Comparing Net And Java The View From 2006kkorovkin
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questionstongdang
 
Prometheus for Monitoring Metrics (Fermilab 2018)
Prometheus for Monitoring Metrics (Fermilab 2018)Prometheus for Monitoring Metrics (Fermilab 2018)
Prometheus for Monitoring Metrics (Fermilab 2018)Brian Brazil
 
Syn framework 4.0 and sql server
Syn framework 4.0 and sql serverSyn framework 4.0 and sql server
Syn framework 4.0 and sql serverEduardo Castro
 

Similar to Windows Communication Foundation (WCF) Best Practices (20)

Wcf best practices
Wcf best practicesWcf best practices
Wcf best practices
 
Take Your Web Development To The Next Level With These Top 2 Libraries
Take Your Web Development To The Next Level With These Top 2 LibrariesTake Your Web Development To The Next Level With These Top 2 Libraries
Take Your Web Development To The Next Level With These Top 2 Libraries
 
Enterprise Library 2.0
Enterprise Library 2.0Enterprise Library 2.0
Enterprise Library 2.0
 
Web Service Security
Web Service SecurityWeb Service Security
Web Service Security
 
"Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment""Running CF in a Shared Hosting Environment"
"Running CF in a Shared Hosting Environment"
 
Stateful mock servers to the rescue on REST ecosystems
Stateful mock servers to the rescue on REST ecosystemsStateful mock servers to the rescue on REST ecosystems
Stateful mock servers to the rescue on REST ecosystems
 
Dynamic and modular Web Applications with Equinox and Vaadin
Dynamic and modular Web Applications with Equinox and VaadinDynamic and modular Web Applications with Equinox and Vaadin
Dynamic and modular Web Applications with Equinox and Vaadin
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013
 
07 advanced topics
07 advanced topics07 advanced topics
07 advanced topics
 
MSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF DemystifiedMSDN Unleashed: WPF Demystified
MSDN Unleashed: WPF Demystified
 
WINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATIONWINDOWS COMMUNICATION FOUNDATION
WINDOWS COMMUNICATION FOUNDATION
 
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS SitesAutomated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
 
.NET Intro & Dependency Injection Workshop
.NET Intro & Dependency Injection Workshop.NET Intro & Dependency Injection Workshop
.NET Intro & Dependency Injection Workshop
 
Jeffrey Richter
Jeffrey RichterJeffrey Richter
Jeffrey Richter
 
Debugging java deployments_2
Debugging java deployments_2Debugging java deployments_2
Debugging java deployments_2
 
Dev212 Comparing Net And Java The View From 2006
Dev212 Comparing  Net And Java  The View From 2006Dev212 Comparing  Net And Java  The View From 2006
Dev212 Comparing Net And Java The View From 2006
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questions
 
.net Framework
.net Framework.net Framework
.net Framework
 
Prometheus for Monitoring Metrics (Fermilab 2018)
Prometheus for Monitoring Metrics (Fermilab 2018)Prometheus for Monitoring Metrics (Fermilab 2018)
Prometheus for Monitoring Metrics (Fermilab 2018)
 
Syn framework 4.0 and sql server
Syn framework 4.0 and sql serverSyn framework 4.0 and sql server
Syn framework 4.0 and sql server
 

More from Orbit One - We create coherence

ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...Orbit One - We create coherence
 
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...Orbit One - We create coherence
 
ShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgradeShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgradeOrbit One - We create coherence
 
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...Orbit One - We create coherence
 
OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...Orbit One - We create coherence
 
Social Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefitsSocial Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefitsOrbit One - We create coherence
 
Marketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensionsMarketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensionsOrbit One - We create coherence
 

More from Orbit One - We create coherence (20)

ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
ShareCafé: SharePoint - Een doos vol documenten of dé tool om efficiënt samen...
 
HoGent tips and tricks van een self-made ondernemer
HoGent tips and tricks van een self-made ondernemer HoGent tips and tricks van een self-made ondernemer
HoGent tips and tricks van een self-made ondernemer
 
Het Nieuwe Werken in de praktijk
Het Nieuwe Werkenin de praktijkHet Nieuwe Werkenin de praktijk
Het Nieuwe Werken in de praktijk
 
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
ShareCafé: Office365 - Efficiënt samenwerken met minimum aan kosten en comple...
 
ShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgradeShareCafé 3 - Geef je samenwerking een technologische upgrade
ShareCafé 3 - Geef je samenwerking een technologische upgrade
 
ShareCafé 2 - Werk slimmer door geïntegreerde tools
ShareCafé 2 - Werk slimmer door geïntegreerde toolsShareCafé 2 - Werk slimmer door geïntegreerde tools
ShareCafé 2 - Werk slimmer door geïntegreerde tools
 
ShareCafé 1: Hou de Nieuwe Werker gemotiveerd
ShareCafé 1: Hou de Nieuwe Werker gemotiveerdShareCafé 1: Hou de Nieuwe Werker gemotiveerd
ShareCafé 1: Hou de Nieuwe Werker gemotiveerd
 
Business value of Lync integrations
Business value of Lync integrationsBusiness value of Lync integrations
Business value of Lync integrations
 
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
OneCafé: De toekomst van ledenorganisaties met behulp van CRM en informatie-u...
 
Identity in the cloud using Microsoft
Identity in the cloud using MicrosoftIdentity in the cloud using Microsoft
Identity in the cloud using Microsoft
 
OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...OneCafé: The future of membership organizations facilitated by CRM and collab...
OneCafé: The future of membership organizations facilitated by CRM and collab...
 
OneCafé: The new world of work and your organisation
OneCafé: The new world of work and your organisationOneCafé: The new world of work and your organisation
OneCafé: The new world of work and your organisation
 
Social Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefitsSocial Computing in your organization using SharePoint: challenges and benefits
Social Computing in your organization using SharePoint: challenges and benefits
 
Wie is Orbit One Internet Solutions
Wie is Orbit One Internet SolutionsWie is Orbit One Internet Solutions
Wie is Orbit One Internet Solutions
 
Azure Umbraco workshop
Azure Umbraco workshopAzure Umbraco workshop
Azure Umbraco workshop
 
Marketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensionsMarketing Automation in Dynamics CRM with ClickDimensions
Marketing Automation in Dynamics CRM with ClickDimensions
 
Office 365, is cloud right for your company?
Office 365, is cloud right for your company?Office 365, is cloud right for your company?
Office 365, is cloud right for your company?
 
Who is Orbit One internet solutions?
Who is Orbit One internet solutions?Who is Orbit One internet solutions?
Who is Orbit One internet solutions?
 
Azure and Umbraco CMS
Azure and Umbraco CMSAzure and Umbraco CMS
Azure and Umbraco CMS
 
Ingredients of the new world of work
Ingredients of the new world of workIngredients of the new world of work
Ingredients of the new world of work
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Windows Communication Foundation (WCF) Best Practices

  • 1. 28 July, 2011 Windows Communication Foundation (WCF) Best Practices
  • 2. Don't build a WCF service ! Unless you have a good reason for it: Security reasons (business Logic in perimeter network) Shared business logic (multiple apps or non .NET apps) Heavy resource consumption (long-running?) Separate maintainable Separate scalable 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 2
  • 3. Know the tools! Svcutil.exe SvcConfigEditor.exe SvcTraceViewer.exe REST starter kit AppFabric Web Services Software Factory (WSSF) http://servicefactory.codeplex.com/ Enterprise Library (EntLib) Exception Handling Application Block Logging Application Block Validation Application Block 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 3
  • 4. Additional tools on CodePlex http://wcfloadtest.codeplex.com takes a WCF trace file and a WCF client proxy, or a WCF interface contract, and generates a C# unit test that replays the same sequence of calls found in the trace file. The unit test can then be used to load-test the target http://wcfcontrib.codeplex.com/ library with infrastructure implementations for client and service communications http://wcfsecurity.codeplex.com/ http://wcfextensions.codeplex.com/ WCF Compression Channel 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 4
  • 5. Service best practices Separate contract from implementation Contract (interface) first (http://wscfblue.codeplex.com/) Define services in a class library, not directly in a host project Layering Separate Service Layer Instance model Change to Per Call as default Session / Singleton – use only when needed 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 5
  • 6. Exception Handling (I) For operation specific exceptions Try/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 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 6
  • 7. Exception Handling (II) If you throw FaultExceptions Part of the API you are exposing For global exception handling from services Use an error handler Include exception details in debug builds only !! 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 7
  • 8. Hosting Favor WAS Hosting when on Windows Server 2008 Multiple protocol support IIS Hosting model and tools Use IIS hosting for external HTTP only Favor self-hosting for stateful services, callbacks, .NET Service Bus, debugging Have 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 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 8
  • 9. When you self host … Do not put ServiceHost in a using statement in production code Dispose can throw an exception that masks the real exception thrown from Open call Explicitly call Close in try/catch and log/ deal with exception in catch 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 9
  • 10. Client Proxy Classes (I) Use static proxy class when possible instead of ChannelFactory Connection caching in the base class in 3.5 Place for encapsulation of common patterns Hand-code or generate proxy classes for internal services Less bloated code Share service contract and data contracts through libraries Explicit control over config file 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 10
  • 11. Client Proxy Classes (II) Add Service Reference for external services or when you want an async API on the client Clean up config after it messes it up Make sure to add references to data contract libraries before adding the service reference to avoid duplicate definitions Live with the duplicate service contract definition instead of needing to repeatedly clean up the proxy code 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 11
  • 12. Client Proxy Management Cache client proxies if frequent calls to avoid session establishment cost If secure / reliable session enabled Have to deal more cautiously with faulted proxies Check proxy state before using Get rid of proxy after exception Don’t put proxies in a using statement Dispose call might throw exception and mask real exception Explicitly close in a try/catch block, and if Close throws an exception, Abort the proxy to ensure resource clean up 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 12
  • 13. Client Exception Management All exceptions thrown from a service call derive from CommunicationException FaultException<T> always an explicit error returned from the service Simple approach: Any exception from a proxy call, safe close the proxy Advanced approach: FaultException<T> - proxy is reusable 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 13
  • 14. Data Contracts Avoid XmlSerializer and MessageContracts except for interoperable scenarios and REST services Favor data contracts over serializable types More explicit model, better control over what the client sees Implement IExtensibleDataObject Avoids dropping data that the service / client does not understand Avoid passing complex .NET specific types for interoperable services DataSets and Exception types 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 14
  • 15. SOAP vs REST Favor SOAP services when you are writing a service that only your code will consume Favor REST services for publicly exposed, data oriented services 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 15
  • 16. Don't forget XmlNamespace settings By default WCF puts the “http://tempuri.org/”  namespace in your wsdl and contracts. Normally you don’t want this. You can control this from three places: In your config file in the services/service/endpoint/bindingNamespaceattribute In your servicecontract: [ServiceContract(Namespace="http://myuri.net/")]  In your servicebehavior: [ServiceBehavior(Namespace="http://myuri.net/")] 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 16
  • 17. More subtle things with WCF One-way !? One-way is not always really one-way even when doing oneway, closing a client can block until the service side is done this is happening in quite some cases where bindings are configured to maintain sessions. it happens for example with Message security and or reliable session support (WS-ReliableMessaging). 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 17
  • 18. The limits of reliable Messaging with WCF (I) Messages still can get lost with this mechanism if for example the service is shutdown IIS reset If you need end-to-end durable reliable messaging with full support for transactional I/O you need an infrastructure that's in control of both ends of the communication NetMsmqBinding. MSMQ messages are limited to 4 MB 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 18
  • 19. The limits of reliable Messaging with WCF (II) If you are mostly worried about not losing messages under less-than-optimal networking conditions or require session support the reliable session support in WCF is the right choice isn’t very handy with load balancers Sticky session/session affinity 28 July, 2011 Windows Communication Foundation (WCF) Best Practices 19
  • 20. 20 Windows Communication Foundation (WCF) Best Practices 28 July, 2011