Dynamic Reconfiguration
This sample demonstrates the Windows Communication Foundation (WCF) routing service. The routing service is a WCF component that makes it easy to include a content-based router in your application. This sample adapts the standard WCF Calculator Sample to communicate using the routing service. This sample shows how the routing service can be dynamically reconfigured during runtime.
Note: |
---|
The samples may already be installed on your computer. Check for the following (default) directory before continuing.
<InstallDrive>:\WF_WCF_Samples
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.
<InstallDrive>:\WF_WCF_Samples\WCF\Basic\RoutingServices\DynamicReconfiguration
|
Sample Details
To dynamically reconfigure the routing service during runtime, this sample fires a timer every five seconds that creates a new RoutingConfiguration object and applies it. This configuration references either the regular Calculator endpoint or the Rounding Calculator endpoint. The Calculator Client application has its messages returned from one service or the other, depending on which one the routing service is configured to route to at that time.
The routing service’s capabilitiy for dynamic reconfiguration through a custom behavior is used. This custom behavior attaches a service extension, which contains a simple thread timer that fires every five seconds, which results in a callback to the UpdateRules
method. This callback creates and applies the new routing configuration. In an actual deployment, this callback would likely be accomplished as a result of some other type of event, such as a SQL-Event notification, or a WS-Discovery announcement.
To use this sample
Using Visual Studio 2010, open DynamicReconfiguration.sln.
To open Solution Explorer, select Solution Explorer from the View menu.
Press F5 or CTRL+SHIFT+B in Visual Studio.
If you would like to auto-launch the necessary projects when you press F5, right-click the solution and select Properties. Select the Startup Project node under Common Properties in the left pane. Select the Multiple Startup Projects radio button and set all of the projects to have the Start action.
If you build the project with CTRL+SHIFT+B, you must start the following applications:
Calculator Client (./CalculatorClient/bin/client.exe)
Calculator Service (./CalculatorService/bin/service.exe)
Routing Calculator Service (./RoundingCalcService/bin/service.exe)
RoutingService (./RoutingService/bin/RoutingService.exe)
In the console window of the Calculator Client, press ENTER to start the client and to call the Calculator service operations.
The routing service routes messages to the Rounding Calculator and to the regular Calculator alternately as the routing configuration changes dynamically every five seconds. Depending on which endpoint the routing service is configured to send messages to there are different outputs in the client console window.
Continue pressing ENTER repeatedly over more than five seconds and observe the change in the results from the service.
The following is the output returned if the Router Service is configured to route messages to the Rounding Calculator service.
Add(100,15.99) = 116
Subtract(145,76.54) = 68.5
Multiply(9,81.25) = 731.2
Divide(22,7) = 3.1The following is the output returned if the routing service is configured to route messages to the regular Calculator service.
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714
The Calculator Service and the Rounding Calculator Service also print out a log of the operations invoked to their respective console windows.
In the client console window, type “quit” and press ENTER to exit.
Press ENTER in the services console windows to terminate the services.
Scenario
This sample demonstrates the router acting as a content-based router allowing multiple types or implementation of services to be exposed through one endpoint.
Real World Scenario
Contoso wants to virtualize all of their services to expose only one endpoint publicly through which they offer access to multiple different types of services. In this case they utilize the routing service’s content-based routing capabilities to determine where the incoming requests should be sent.