BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News WCF Communication Options in the .NET Framework 3.5

WCF Communication Options in the .NET Framework 3.5

This item in japanese

David Chappell, Principal of Chappell & Associates, presents the various communication styles provided by Windows Communication Foundation (WCF) in his white paper called "Dealing with Diversity: Understanding WCF Communication Options in the .NET Framework 3.5".

Windows Communication Foundation is Microsoft's approach of providing a single programming model for the diverse set of communication options faced when developing distributed systems. The set of options ranges from inter process communication to peer-to-peer networking. In the past each communication model dictated a specific programming model. "By providing a common programming model for many kinds of communication, it can help developers work more effectively with diversity", says David Chappell.

The whitepaper starts by introducing the two main WCF concepts that are responsible for working with diversity:

From the beginning, WCF’s creators recognized that applications had diverse communication needs. They also believed that new kinds of communication were certain to appear. To address this reality, WCF provides a general architecture for supporting different communication styles. The two big ideas in this architecture are channels and bindings [...].

In WCF every interaction is viewed as a message exchange. Messages consist of a payload and an arbitrary amount of infrastructure data including its transport. In order to cope with the diverse set of existing and future communication alternatives, WCF introduced the channel model. Each channel is dedicated to a specific infrastructure aspect, e.g. security or reliability. The complete set of infrastructure needs of a single communication option is handled by a predefined or custom channel stack:

Whether acting as a client, a service, or both, all software that communicates via WCF relies on one or more channels. [...] a stack of channels is created between a WCF client or service and the communication mechanism it relies on. The lowest channel in this stack always does the same job: It maps the message being sent to whatever mechanism is used to transport that message. Accordingly, this bottom component is known as the transport channel.

WCF allows to easily configure and define a channel stack by introducing bindings:

By specifying a particular binding, a WCF client or service implicitly creates a channel stack that implements a particular set of communication behaviors. [...] The service defined by a particular WCF interface might be accessible via just one binding [...] or simultaneously accessible via more than one binding [...].

After explaining the architecture David Chappell presents all communication options offered by the .NET Framework 3.5:

SOAP and WS-* Web Services

Being Microsoft's approach to service-oriented architecture WCF is built to develop SOAP/WS-* web services:

  • WCF allows to send SOAP/WS-* messages over an arbitrary transport, e.g. HTTP or TCP.
  • The most important WS-Specifications are supported - MSDN provides an extensive overview of Web Services Protocols Supported by System-Provided Interoperability Bindings in .NET Framework 3.5.
  • Services can be forced to conform to the Web Services Interoperability Organization (WS-I) Basic Profile 1.0.
  • WCF provides a set of predefined bindings for the most common web service scenarios. 

Binary Communication between WCF Applications

In the event of WCF-To-WCF communication

WCF supports communication using a more efficient binary encoding. Rather than sending standard XML-based SOAP messages over HTTP, a developer can choose to send a more efficient representation of the same information directly over TCP.

RESTful Web Services

Since the REST approach to web services gains more and more popularity, WCF supports a RESTful style in the .NET Framework 3.5. Although the fact that the first version of WCF was focused on SOAP-based services, the "quite general channel model makes adding support for RESTful communication straightforward". At first WCF messages have to get rid of the SOAP envelope and its headers, which is accomplished by using the newly added WebHttpBinding:

Unlike the [other] HTTP-based bindings [...] this one uses an encoding option that’s new in the .NET Framework 3.5 release of WCF: WebMessageEncoding. This option doesn’t add or remove SOAP headers. Instead, it implements three different options for representing content: text-based XML encoding, JSON encoding, and opaque binary encoding, which is useful for things such as conveying JPEG files. And like its fellow HTTP bindings, WebHttpBinding can also be configured to use HTTPS for greater security.

Operations are mapped to HTTP verbs, e.g. GET, PUT, POST or DELETE, by annotating the WCF Service Contract with the WebGet or WebInvoke attributes. In Because the RESTful style "necessarily means working with URIs", WCF provides a means of managing "large numbers of similar URIs": URI templates. "The goal of these templates is to make it easier for developers to express URI patterns and work with URIs that match those patterns".

POX and Syndication (RSS, ATOM)

Sending Plain Old XML (POX) messages or using a syndication format is supported by using WCF's RESTful model:

POX, RSS, and ATOM are all formats—they’re not protocols. Because of this, no special WCF binding is required to use them. All are usually sent directly over HTTP, with no SOAP header, and so the best binding choice is typically WebHttpBinding.

Communication with Line-Of-Business (LOB) Applications

WCF supports developing clients that communicate with applications that do not provide a web service interface:

One important example of this is communicating with a line-of-business (LOB) application, such as SAP. [...] 

Allowing this is the goal of the WCF Line-of-Business (LOB) Adapter SDK. As the “SDK” in its name suggests, this technology doesn’t itself include any adapters. Instead, it provides tools and a runtime environment to help create adapters to LOB applications. These adapters can then be used by application developers to create WCF clients that use the services of an LOB application just as if that application were an ordinary WCF service.
 

Communication via Message Queues

In order to communicate with message queues

[...] WCF provides an MSMQ transport channel. To use queued communication, a developer creates a standard WCF service, marking its interface and methods with the ServiceContract and OperationContract attributes as usual. Each operation in this interface must also be marked with the IsOneWay property on the OperationContract attribute [...]

Only binary messages are send via MSMQ, either wrapped by a SOAP envelope or without using a SOAP envelope.

Communication via Windows Peer-To-Peer Networking

Windows peer-to-peer networking  is mainly used for collaboration scenarios. Single PCs act as clients and servers (peers) within a peer system. 

As usual, WCF applications can use Windows peer-to-peer networking by specifying the correct binding. The NetPeerTcpBinding [...] relies on a transport channel that’s specific to peer communication. This binding also puts in place a PnrpPeerResolver channel that handles addressing for messages sent to a particular graph of peer systems.
 

Interprocess Communication

WCF supports [communication between processes on the same machine] using the NetNamedPipeBinding [...]. Rather than relying on a transport channel that implements a networking protocol, such as HTTP or TCP, this binding uses a transport channel that communicates via named pipes, a standard Windows mechanism for interprocess communication.

Custom Communication

WCF provides many ways of extending and customizing communication options. Developers may create custom channels, custom bindings and customize the existing bindings. David Chappell presents Microsoft BizTalk Services, that "provide an interesting illustration of this".

 

According to David Chappell "a general-purpose platform for communication makes good sense". WCF is "supporting a diversity of communication styles within a common framework", that can easily be expanded or customized.

Rate this Article

Adoption
Style

BT