Chapter 13: Routing Messages


image from book Download CD Content

Overview

After completing this chapter, you will be able to:

  • Describe how the WCF runtime for a service dispatches messages to operations.

  • Build a WCF service that transparently routes client requests to other WCF services.

  • Describe how WCF conforms to the WS-Addressing specification.

When a client application sends a message to a WCF service, it sends the request through an endpoint. If you recall, an endpoint specifies three pieces of information: an address, a binding, and a contract. The address indicates where the message should go; the binding identifies the transport, format, and protocols to use to communicate with the service; and the contract determines the messages that the client can send and the responses it should expect to receive. A service can expose multiple endpoints, each associated with the same or a different contract. When a WCF service receives a message, it has to examine the message to determine which service endpoint should actually process it. You can customize the way in which WCF selects the endpoint to use, and this provides a mechanism for you to change the way in which WCF routes messages within a service.

Sometimes it is useful to forward messages to entirely different services for handling. Suppose that client applications send requests to various WCF services hosted by an organization, but all of these requests actually go through the same front-end service, which acts as a firewall to the real WCF services. The front-end service can run on a computer forming part of the organization’s perimeter network, and the computers hosting the real WCF service servers can reside in a protected network inside the organization. The front-end service can act as a router, forwarding requests on the real services by examining the action or address in each message. This mechanism is known as address-based routing. The front-end service can also filter messages, detecting rogue requests and blocking them, depending on the degree of intelligence you want to incorporate into the front-end service logic.

An alternative scheme is to route messages based on their contents rather than the action being requested. This mechanism is known as content-based routing. For example, if you are hosting a commercial service, you might offer different levels of service to different users depending on the fees that they pay you. A “premium” user (paying higher fees) could have requests forwarded to a high-performance server for a fast response, whereas a “standard” user (not paying as much) might have to make do with a lower level of performance. The client application run by both categories of user actually sends messages to the same front-end service, but the front-end service examines some aspect of the message, such as the identity of the user making the request, and then forwards the message to the appropriate destination. A front-end service can also provide other features such as load-balancing. Requests from client applications arrive at a single front-end server, which uses a load-balancing algorithm to distribute requests evenly across all servers running the WCF service.

In this chapter, you will look at techniques you can use to handle scenarios such as these.




Microsoft Windows Communication Foundation Step by Step
Microsoft Windows Communication Foundation Step by Step (Step By Step Developer Series)
ISBN: 0735623368
EAN: 2147483647
Year: 2007
Pages: 105
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net