Windows Communication Foundation
Do you write code that needs to communicate with other software? Microsoft's Windows Communication Foundation (WCF) is a single, unified programming model for messaging that supports all communications protocols and transports.
Developers no longer have to learn to use every communications protocol. Tools and project templates are available for WCF in Visual Studio 2008, which is in beta now and expected to ship next year. These tools -- combined with the use of attributes and configuration files -- make for a highly productive dev environment.
Part of .NET Framework 3.0, WCF enables the development of secure, reliable, transacted services that interoperate with non-Microsoft platforms. It combines and extends the capabilities of Microsoft's existing distributed systems technologies, including Enterprise Services, MSMQ, .NET Remoting, WSE v3.0 and ASMX.
WCF has three main strengths: Interoperability, productivity and a service-oriented development focus. It supports the common Web service Basic Profile 1.0 and the WS-* specifications.
With service-orientation, you retain the benefits of self-describing applications, explicit encapsulation and dynamic loading of functionality. What changes is the metaphor with which you accomplish it. Instead of using method invocation on an object reference, developers rely on message passing. In addition, to support dynamic loading of service-based functionality, a schema is used to describe the structure of messages, a behavioral contract to define acceptable message exchange patterns and policy to define service semantics.
ABC's of WCF
In WCF, you create a service endpoint from an "Address," a "Binding" and a "Contract"-the ABC's of creating a WCF service. In developing a service, you run through the ABC's in reverse and create the contract first. A contract is built as an interface in .NET, and each method to be exposed via the service endpoint is marked with the [OperationContract] attribute.
Once the contract is defined, the address, binding, contract and any other miscellaneous configuration can be specified in an XML config file that you can edit in Visual Studio 2008 with the WCF Configuration Editor tool. The binding specifies any channels to be used and includes any transports and protocols that the messaging takes place over. The address is an identification of where the endpoint is; the address format depends upon the binding chosen.
Using the unified programming model that WCF provides enables many different messaging scenarios:
- REST Web HTTP, in .NET 3.5, is a binding that includes template-based URI addressing, explicit support for content types and HTTP GET-based retrieval of information.
- Syndication Web HTTP, in .NET 3.5, is a binding that formats data using RSS or ATOM syndication formats. Internet Explorer 7.0 can be used as a client for this kind of service.
- AJAX Web HTTP, in .NET 3.5, is a binding for services that are compatible with AJAX clients where a Web service may be called from a Web browser without a full-page update. These services support the JSON encoding format and are highly scalable services supporting ASP.NET AJAX applications.
- Basic HTTP is a binding that has binary compatibility with WS-I Basic Profile Web services. These are the Web services that can be built with Visual Studio .NET 2003 and Visual Studio 2005 and are known as ASMX SOAP
- .NET TCP is a binding that offers high performance using the TCP transport and binary (non-XML) formatting. This is an optimal binding for cross-machine communications where both endpoints are using WCF.
- .NET named pipe is a binding that uses shared memory to message between two processes on a single machine. Although this binding requires both service and client to be on the same machine it provides the most performance possible in that scenario.
- .NET peer is a binding for messaging between peer nodes on a network.
Lastly, there's a new implementation of WCF coming out at the same time as .NET Framework 3.5. The .NET Compact Framework 3.5 includes a subset of WCF features, including Web service support with WS-Security and a new store and forward communications channel. The store and forward channel uses activesync and e-mail to send and receive messages. This means that messages can be addressed to an individual mobile device by using the e-mail address.
[click image for larger view]
|Visual Studio 2008 will include the WCF Configuration Editor tool for creating address, binding and contract configs.
Messages can also be sent while the device is offline as they're stored in the e-mail account and synchronized when the device goes online for e-mail sync. This enables scenarios that have not been possible before for mobile applications, and it builds on a transport mechanism that's often already in place and reliably configured.
Paul Andrew is a senior product manager for the .NET Framework at Microsoft.