Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

WCF Essentials—A Developer's Primer : Page 6

WCF is an SDK for building service-oriented applications on Windows, letting you use classic CLR programming constructs, such as classes and interfaces, to deploy and consume services. The programming model is declarative and largely attribute-driven.


advertisement
WCF Architecture
This article so far covered all that is required to set up and consume simple WCF services. However, WCF offers immensely valuable support for reliability, transactions, security, and instance activation, all of which rely on the WCF interception-based architecture.

Having the client interact with a proxy means that WCF is always between the service and the client, intercepting the call and performing pre- and post-call processing. The interpretation starts when the proxy serializes the call stack frame to a message and sends the message down a chain of channels.

WCF offers immensely valuable support for reliability, transactions, security, and instance activation, all of which rely on the WCF interception-based architecture.
Each client-side channel does pre-call processing of the message. The exact structure and composition of the chain depends mostly on the binding. For example, one of the channels is responsible for encoding the message (binary, text, or MTOM), another for passing security call context, another for propagating the client transaction, another for managing the reliable session, another for encrypting the message body (if so configured), and so on. The last channel on the client side is the transport channel, which sends the message over the configured transport to host.

On the host side, the message goes though a chain of channels as well, which perform host-side pre-call processing of the message. The first channel on the host side is the transport channel, which receives the message from the transport. Subsequent channels perform various tasks, such as decryption of the message body, decoding of the message, setting the propagated transaction to the execution thread, setting the security principal, managing the session, and activating the service instance. The last channel on the host side passes the message to the dispatcher. The dispatcher converts the message to a stack frame and calls the service instance. This sequence is depicted in Figure 8.

 
Figure 8: The WCF architecture looks like this.
The interception both on the client and the service side ensures that the client and the service get the runtime environment they require to operate properly. The service instance executes the call and returns control to the dispatcher, which then converts the returned values and error information (if any) to a returned message. The process is now reversed: the dispatcher passes the message through the host-side channels to perform post-call processing, such as managing the transaction, deactivating the instance, encoding the reply, encrypting it, and so on. The returned message goes to the transport channel, which sends it to the client-side channels for client-side post-call processing: decryption, decoding, committing, or aborting the transaction, etc.

The proxy converts the returned message to a stack frame and returns control to the client. Most noteworthy is that almost all points in the architecture provide hooks for extensibility—you can provide custom channels for proprietary behaviors, custom instance management, or custom security. In fact, the standard facilities that WCF offers are all implemented using the same extensibility model.

Working with Channels
You can use channels directly to invoke operations on the service without ever resorting to a SvcUtil-generated proxy. The ChannelFactory<T> class shown in Listing 10 enables you to create a proxy on the fly. You need to provide the constructor with the endpoint—either the endpoint name from the config file or the binding and the address objects, or an endpoint object. Next, use the CreateChannel() method to obtain a reference to the proxy (the top-level channel) and use its methods. Finally, close the proxy by either casting it to IDisposable and calling the Dispose() method or to IClientChannel and calling the Close() method:

ChannelFactory<IMyContract> factory; //Use default endpoint factory = new ChannelFactory<IMyContract>(""); IMyContract proxy1 = factory.CreateChannel(); using(proxy1 as IDisposable) { proxy1.MyMethod(); } IMyContract proxy2 = factory.CreateChannel(); proxy2.MyMethod(); IClientChannel clientChannel = proxy2 as IClientChannel; Debug.Assert(clientChannel != null); clientChannel.Close();

WCF is an SDK for building service-oriented applications on Windows. It enables you to use classic CLR programming constructs, such as classes and interfaces, to deploy and consume services. The programming model is declarative and is largely attribute-driven. WCF interception-based architecture offers built-in facilities for managing many runtime aspects of services, and moving forward, it is the most productive way of building distributed applications on Windows.

The first release of WCF provides many useful facilities for developing services, such as hosting, service instance management, asynchronous calls, reliability, transaction management, disconnected queued calls, and security. The second release of WCF will add service discovery and event publishing and subscribing. WCF requires .NET 2.0 and will be released with Windows Vista. It will be made available on Windows XP SP2 and Windows Server 2003 SP1.



Juval Lowy is a software architect and the principal of IDesign, Inc., a consulting and training company focused on .NET architecture consulting and advanced .NET training. His latest book is "Programming .NET Components, 2nd Edition" (O'Reilly, 2005). Juval is a frequent presenter at development conferences and Microsoft's Regional Director for the Silicon Valley. Over the last two years Juval has been part of the Indigo Strategic Design Review process. Microsoft recognized Juval as a Software Legend as one of the world's top .NET experts and industry leaders. Contact him at www.idesign.net
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap