Problem solve Get help with specific problems with your technologies, process and projects.

Beginning Windows Communication Foundation development, Part 3

Our latest Windows Communication Foundation tip considers the use of addresses, caching, security and performance monitoring in WCF.

Windows Communication Foundation has been described as the most important of the .NET Framework 3.0 technologies. has offered some insight into this SOA tool in two previous tips -- Beginning WCF development, Part 1 and, appropriately enough, Beginning WCF development, Part 2 -- and continues to do so with this tip.

We begin with A truly simple example to get started with WCF from Ralf Westphal. This blogger created his sample WCF service because everything else he had seen involved multiple files and multiple languages. Here, in 104 lines of C#, Westphal defines and implements the service, implements and runs the server, and implements the client. "That's my very simplest WCF example. It lets you play around with WCF in a single process. Or you can easily distribute the code across several assemblies," Westphal concludes.

From here, we're going to look at some key Windows Communication Foundation concepts one at a time.

Addresses: Quite simply, an address denotes where a service is located and where a SOAP message is headed; it, along with a binding and a contract, are defined in a service's endpoint. A recent MSDN article, WCF addressing in depth by Aaron Skonnard, offers a few hints for coding addresses.

First, Skonnard notes, there are two fundamental ways to specify an address -- as an absolute address for each endpoint or as a base address with relative paths for each endpoint.

More on Windows Communication Foundation
Beginning WCF development: Part 1 | Part 2

Programming SOA with WCF

Instance management, security in WCF

WCF Security Learning Guide
In addition, it is entirely possible to expose multiple endpoints for a service, if that service has different bindings; on the other hand, if you are exposing multiple endpoints on the same binding, then a single address will do. Finally, it might be worth considering custom address headers for SOAP messages, he says, "[i]n order to accommodate even more sophisticated routing and dispatching logic."

Caching: Caching is important to Windows Presentation Foundation services, as there is always a possibility that messages will be sent from the client faster than they can be processed by the service. It pays, therefore, to have a good caching strategy. Paul Glavich provides such a strategy in a recent blog post, Architecture, WCF Services and Caching. He summarizes it thusly: "Caching is easily implemented by overriding the virtual service method and providing only caching semantics, calling down to base services for actual data where required."

Claims-based security: Both role- and permission-based security models have their drawbacks, so Windows Communication Foundation has introduced a claims-based security model. "A claim describes an individual right or action applicable to a particular resource," Michele Leroux Bustamante writes in Building a claims-based security model in WCF, Part 1. "For example, an identity claim might describe a username, while a proof of possession claim might describe a role, a right to a particular resource, or some other useful information." That article, along with Building a claims-based security model in WCF, Part 2, outlines how to build a claims-based authorization model, implement and customize authorization policies, set permission demands, and work with both security and SAML tokens.

Performance counters: Want to get some real-time monitoring information for your WCF service? It is quite easy, and requires but three lines of code inputted through configuration, Nicholas Allen writes in Enabling Performance Counters. (Allen's blog, for what it is worth, is an excellent source of quick Windows Communication Foundation. The Channels tag and the Service Model tag might be of particular interest.)

WCF and the .NET Compact Framework: Recognizing that Web services and mobile devices, pardon the pun, go hand in hand, Microsoft is bringing a subset of Windows Communication Foundation to mobile devices. Roman Batoukov indicates in Windows Communication Foundation (Compact Edition) and the story of the Lunch Launcher will be limited to channel layer messaging and, therefore, will not offer service model support on mobile devices. This is because, by and large, mobile devices users tend to use email as their message transport channel, Batoukov suggests.

Additional information on Windows Communication Foundation and mobile devices can be found in Mark Prentice's Introduction to WCF for the .NET Compact Framework Messaging Stack. This provides a "Hello World" example using HTTP requests and demonstrates how to create a helper class, create and open a channel, send the message and set up the server to respond to it.

WCF for non-HTML endpoints: We end with a tidbit that addresses XML-RPS, which it the common API for blogging software. That calls for an XML-RPC implementation on Windows Communication Foundation. Writes Clemens Vasters in XML-RPC with WCF:

My XML-RPC implementation is a binding with a special encoder and a set of behaviors. The Service Model programming experience is completely "normal" with no special extension attributes. That means you can also expose the XML-RPC contracts as SOAP endpoints with all the advanced WCF bindings and features if you like.

Vasters adds that this prototype should be available in the main code base for the .NET Framework 3.5.

Dig Deeper on Web services and SOA implementations in the .NET Framework

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.