What's New in WCF 4.0?
An Early Look at Forthcoming WCF Features
October 30, 2009
Exploring WCF Services
LANGUAGES:C#
ASP.NETVERSIONS: .NET 4.0 | WCF
What s New in WCF 4.0?
An Early Look at Forthcoming WCF Features
By Michele Leroux Bustamante
This month s column explores the next generation offeatures to be released with WCF 4.0 when the .NET Framework 4.0 ships.
The .NET Framework 4.0 will be released with Visual Studio2010 bringing with it a plethora of new WCF features. WCF 4.0 will solve manypain points related to configuration, tracing and diagnostics, serialization,and messaging. In addition, this release will include exciting newenterprise-ready features, such as service discovery and routing, and, whencombined with the power of WF 4.0, Workflow Services will greatly simplify howdevelopers incorporate asynchronous programming models to offset expensiveIO-intensive operations and improve overall application performance andthroughput.
To provide you with a well-rounded view of the forthcomingrelease, I ll provide in this article a high-level summary of features we knowwill be released with WCF 4.0. In subsequent articles I ll explore thesefeatures in greater detail.
Simplified Configuration
One of the major pain points experienced by WCF developersis configuration. In WCF 4.0 we can look forward to a significant improvementin this area through configuration defaults, behavior inheritance, and implicitendpoints. Collectively, these features can yield a truly configuration-freeexperience when you host your WCF services.
The idea is that you provide better binding configurationand behavior defaults for your specific application s requirements, and theruntime picks up those defaults when it initializes the ServiceHost. Figure 1illustrates providing default settings for WS2007HttpBinding and severalbehavior defaults. They are noted as defaults by using an empty string ( ) forthe binding and behavior name.
"false"establishSecurityContext="false" /> Figure 1: Bindingand behavior defaults in WCF 4.0.When the ServiceHost is initialized, an endpoint will be createdautomatically for each contract implemented by the service type for each baseaddress provided. When you combine this behavior with default bindingconfigurations and behavior settings, configuration-free hosting actually seemsplausible.Serialization EnhancementsThe new DataContractResolver will provide newextensibility that are hooks useful for customizing CLR type mapping for theDataContractSerializer. This can be useful for simple overrides such asaltering the name and namespace for CLR types written to the wire, foroverriding which CLR types are involved in serialization, and for dynamicallymanaging known types.Queued Messaging ReceiveContextTo guarantee exactly one instance of delivery of messagesfrom a queue in Microsoft Message Queuing (MSMQ), you must work withtransactional queues and the WCF service operation must participate in theplayback transaction. If an exception is thrown while processing the message,the service can guarantee the message doesn t get lost by returning it to thequeue either the originating queue, the dead letter queue, or a poisonmessage queue, depending on configuration and MSMQ versions. This is quiteuseful, but has limitations in that there is no way to ensure the same serviceprocesses the failed message the next time it is pulled from the queue, not tomention that transactions are expensive.WCF 4.0 introduces ReceiveContext as an alternativetechnique for processing queued messages. The thrust of this new technique isthat the message is not pulled from the queue until the message is successfullyprocessed by the service. A ReceiveContext is associated with the message onceit is peeked by a service and if an exception is thrown and the messagecannot be completed, it remains in the queue but also can remain locked bythat particular service to retry processing. This reduces overhead because themessage need not be transmitted over the network again to another service.ReceiveContext provides a way to explicitly complete the message so that it canbe removed from the queue on success. ReceiveContext guarantees at least onedelivery when used without transactions, and when composed with transactions itguarantees exactly one delivery with performance benefits.Web ProgrammingSince the release of .NET 3.5 it has been much easier tobuild WCF services that bypass SOAP processing requirements, includingPlain-Old-XML (POX), Java Script Object Notation (JSON), and RepresentationalState Transfer (REST) the latter of which is an architectural approach fordesigning POX or JSON services. These techniques fall under the Web programmingmodel for WCF services. Microsoft also released the WCF REST Starter Kit, whichconsiderably improves productivity when building services for this Webprogramming model. The WCF REST Starter Kit includes the following:§ Many Visual Studio templates for the most commonscenarios for POX, REST, and Atom/Pub.§ New features to support better error reportingto the browser. Supporting types are WebProtocolException and new behaviorsinstalled with WebServiceHost2 and WebServiceHost2Factory.§ A much needed extensibility hook for HTTPrequests through RequestInterceptor.§ The ability to more easily override HTTP verbsfor clients that don t support PUT and DELETE.§ Cached operation responses withWebCacheAttribute.§ Tons of code samples illustrating how to workwith these features.The idea behind releasing the starter kit was to get thesefeatures into the hands of RESTful WCF developers so they could providefeedback on features so .NET 4.0 can include the most relevant features andinclude any refinements. Thus, many of these features will be included in theWCF 4.0 feature set.Basic Profile 1.2As you may be aware, there are a number of standards bodiesthat drive specifications implemented by platforms like WCF, including W3C (http://www.w3c.org), OASIS (http://www.oasis-open.org),and WS-I (http://www.ws-i.org).The goal of the latter is to simplify how the plethora of standards isimplemented in vendor platforms. In WCF, BasicHttpBinding supports BasicProfile (BP) 1.1, which is based on SOAP 1.1. This profile is grossly out ofdate, and does not support WS-Addressing semantics or MTOM. Thus, a new profilewas born: BP 1.2. This new profile addresses errata for BP 1.1 and includessupport for WS-Addressing and MTOM. WCF 4.0 will support this profile. Do not confuse BP 1.2 (based on SOAP 1.1)with BP 2.0 (based on SOAP 1.2), which is still a work in progress.Service DiscoverySpeaking of protocol support, WCF 4.0 includes along-awaited implementation of WS-Discovery. This specification documents a multicastprotocol that issues SOAP messages over UDP. Services that implement discoveryendpoints can receive probe messages from clients that wish to discoverservices within their subnet. In addition, services can announce themselves toclients listening for announcements. Figure 2 illustrates the flow ofcommunication between clients and services.
Figure 2: Discovery probes andannouncements from a high level.Discovery messaging works because communication endpointsare well-known UDP addresses. WCF 4.0 makes it very easy to implement servicediscovery with a few simple steps: Services that wish to be discoverable implementa discovery endpoint and enable discovery with a service behavior. Services that wish to send discoveryannouncements enable announcements as part of the discovery behavior. Clients that wish to probe services within thesubnet use a built-in DiscoveryClient and supply heuristics for searching forthe desired services.There are many architectural scenarios that can implementdiscovery, and this will be the subject of a future article.Router ServiceRouters can be very useful when you need to introduce loadbalancing using custom heuristics, content-based or priority routing,versioning scenarios, or when you need to introduce a security boundary betweenremote clients and services that live behind the DMZ. Implementing a customrouter is a significant undertaking, but WCF 4.0 aims to relieve this effort bysupplying us with a built-in router equipped to work with one-way, two-way, andduplex messaging.You host the new RouterService as you would any other WCFservice, then configure routing rules using a filter table and a set ofassociated filters. The filters are ultimately evaluated to determine thecorrect downstream service endpoint to forward messages to. This architectureis illustrated in Figure 3.
Figure 3: Configuring the RouterService in WCF 4.0.Many filtering options are available through a simpleconfiguration, such as XPath queries for content-based routing and queriesbased on the SOAP action header. There also are extensibility hooks availablefor deeper control over filters and routing decisions.Workflow ServicesNew features in WCF 4.0 and WF 4.0 yield a more compellingstory for implementing services operations as Workflow Services. In .NET 3.5one usually restricted the use of Workflow Services to asynchronous,long-running processes that could withstand the overhead of the WorkflowRuntime. In .NET 4.0, the Workflow Runtime performance is significantly improved,thus removing that limitation. Instead, the choice to use Workflow Services ispurely driven by design choices and singular benefits, such as:§ Increased visibility through correlated WFtracking and WCF tracing events.§ Greatly simplified approach to implementingasynchronous programming models; for example, issuing downstream service callsin parallel and correlating responses.§ Implementing declarative (XAMLX) services, whichprovide an alternative to deploying, updating, and versioning and make it possibleto deploy Workflow Services to the cloud.High-performance TracingWCF 4.0 trace events are based on Event Tracing forWindows (ETW), which significantly enhances tracing and diagnosticsperformance. From a high level, the architecture of ETW is simple: eventproviders push events to sessions under a registered provider ID, controllersare used to enable or disable sessions that collect events and associateproviders with sessions, sessions can optionally persist events to a log, and consumerapplications listen to real-time session events or pick events up from tracelogs. ETW is buffered to reduce contention when persisting events to afile-based trace log. Figure 4 illustrates this architecture.
Figure 4: WCF tracing and WF trackingwith ETW.Both WCF and WF share the same ETW event provider so thata correlated view can be presented for WF tracking events and WCF tracingevents which is very useful for troubleshooting Workflow Services. Furthermore,Dublin provides a friendly interface to enabling and configuring tracking andtracing through IIS Manager.ConclusionThe new features in WCF 4.0 traverse a number of areas,including configuration, tracing, serialization, message queuing, servicediscovery, routing, and workflow services. All of these new featuresspecifically address pain points that developers experienced with earlierversions of WCF. I ll explore these enhancements in greater detail in futurecolumns.Michele LerouxBustamante is Chief Architect of IDesign Inc., Microsoft Regional Directorfor San Diego, and Microsoft MVP for Connected Systems. At IDesign Micheleprovides training, mentoring, and high-end architecture consulting servicesfocusing on Web services, scalable and secure architecture design for .NET,federated security scenarios, Web services, interoperability, and globalizationarchitecture. She is a member of the International .NET Speakers Association(INETA), a frequent conference presenter, conference chair for SD West, and isfrequently published in several major technology journals. Michele also is onthe board of directors for IASA (International Association of SoftwareArchitects), and a Program Advisor to UCSD Extension. Her latest book is Learning WCF (O Reilly, 2007; updated in 2008);visit her book blog at http://www.thatindigogirl.com.Reach her at mailto:[email protected], orvisit http://www.idesign.netand her main blog at http://www.dasblonde.net.Additional Resources§ LearningWCF (O Reilly, 2007; reprinted for VS 2008, July 2008): http://www.thatindigogirl.com(get all the book code here!)§ Michele s blog: http://www.dasblonde.net§ IDesign: http://www.idesign.net
Read more about:
MicrosoftAbout the Author
You May Also Like