Pages






Tuesday, February 15, 2011

WCF Essentials-A Developer’s Primer

Windows Communication Foundation (WCF) provides a run-time environment for your services, enabling you to expose CLR types as services and to consume services as CLR types. Although in theory you can build services without it, in practice, WCF significantly simplifies this task. WCF is Microsoft’s implementation of a set of industry standards defining service interactions, type conversion, marshaling, and various protocols’ management. Because of that, WCF provides interoperability between services, and it promotes productivity, including the essential off-the-shelf plumbing required by almost any application. This article describes the essential concepts and building blocks of WCF and its architecture, enabling you to build simple services. Future articles in this series will address specific aspects, such as transaction management and security.

What Are WCF Services?

A service is a unit of functionality exposed to the world. In that respect, it is the next evolutionary step in the long journey from functions to objects to components to services. Service-orientation (SO) is an abstract set of principles and best-practices for building SO applications, which are largely beyond the scope of this article.

"
WCF provides a run-time environment for your services, enabling you to expose CLR types as services and to consume services as CLR types.
"

A service-oriented application (SOA) aggregates services into a single logical application (Figure 1), similar to the way a component-oriented application aggregates components or an object-oriented application aggregates objects. The services can be local or remote, developed by multiple parties using any technology, they can be versioned independently, and even executed on different timelines. Inside a service, you will find concepts such as languages, technologies, platforms, versions, and frameworks, yet between services, only prescribed communication patterns are allowed.

Click for a larger version of this image.

Figure 1: This is a sketch of a service-oriented application.

Clients and services interact by sending and receiving messages. Messages may transfer directly from client to service or via an intermediary. With WCF, all messages are SOAP messages. Note that the messages are independent of transport protocols-unlike Web services, WCF services may communicate over a variety of transports, not just HTTP.

With WCF, the client never interacts with the service directly, even when dealing with a local, in-memory service. Instead, the client always uses a proxy to forward the call to the service. WCF allows the client to communicate with the service across all execution boundaries. On the same computer (see Figure 2), the client can consume services in the same application domain, across application domains in the same process, or across processes. Across computer boundaries (Figure 3), the client can interact with services in its intranet or across the Internet. Because all interactions are done via a proxy, WCF maintains the same programming model for the local and remote cases, thus not only enabling you to switch locations without affecting the client, but also significantly simplifying the application programming model. Most all of the WCF functionality is included in a single assembly called System.ServiceModel.dll in the System.ServiceModel namespace.

Click for a larger version of this image.

Figure 2: This is the same machine communication using WCF.

Click for a larger version of this image.

Figure 3: This is cross-machine communication using WCF.

Service Address

In WCF, every service is associated with a unique address. The address provides two important elements: the location of the service and the transport protocol used to communicate with the service. The location portion of the address indicates the name of the target computer, site, or network, a communication port, pipe, or queue, and an optional specific path or URI. As for transports, WCF 1.0 supports the following:

  • HTTP
  • TCP
  • Peer network
  • IPC (Inter-Process Communication over named pipes)
  • MSMQ

Addresses always have this format:

[base address]/[optional URI]

The base address is always in this format:

[transport]://[machine or
domain][:optional port]

Here are a few possible addresses for services:

http://localhost:8001
http://localhost:8001/MyService
net.tcp://localhost:8002/MyService
net.pipe://localhost/MyPipe
net.msmq://localhost/private/MyService


SOURCE:http://www.code-magazine.com/Article.aspx?quickid=0605051

0 comments: