Exercise 10: Backup Lists

You have seen how routing can be used to bridge protocols and route based on content. In this exercise, you will see how you can add list of alternate services to be used in the event that the primary service cannot be contacted.

Figure 35

The Routing Service using a backup list

Task 0 – Opening the Solution

To begin this exercise you can use the solution you finished from Exercise 9. Alternatively, you can follow the following steps to begin with Exercise 10.

  1. Open the starting solution for Exercise 10 located under the Source\Ex10-BackupLists\Begin(choosing the folder that matches the language of your preference.) Use it as the starting point for this exercise.
  2. Press CTRL+SHIFT+B to build the solution.

Task 1 – Adding a Bad Endpoint

In this task, you will modify the configuration to call an endpoint that does not exist. This will allow us to see how the router service behaves when it cannot contact an endpoint.

  1. Open the Web.config file from the RouterService project.
  2. Add the badEndpoint definition to the client section as shown.

    (Code Snippet - What is new in WCF4 Lab – badEndpoint XML)

    Web.config

    <client>
    <endpoint name="badEndpoint" address="https://localhost:404/bad/endpoint" binding="wsHttpBinding" contract="*" />

  3. Now, in order to get a communication failure, you must actually direct the Routing Service to send to this endpoint. Replace one of the good calculator endpoints in the filter table. In the filter table definition, change the entry that references the roundingCalculatorEndpoint to instead reference badEndpoint

    XML

    <filterTables>
    FakePre-2cd5f5c2e24d42d7a95dc941a5a3730f-5efdcb0f33ac459294d25511dc9d5450FakePre-be1d100333c34650af093151986d4926-ae0501bf677541c0ad6b20d9612b7622FakePre-0f9fefab5e814979b9a9d6891a047367-e762b7dbefa94d2a9fa7fbf385693afaFakePre-abedc063f2a0429fa7a7c6e6098e76e7-2258aa2b5e884085a0f7ce2ac825b872

Task 2 – Observing the Routing Fail

  1. Right-click the Ex10-BackupLists solution and select Set StartUp Projects.
  2. Select Multiple startup projects and set all the projects to Start.
  3. Press F5 to debug the solution.
  4. In the CalculatorClient select Routed HTTP connection and click on the Use Rounding button to add the rounding message header.
  5. Click on Invoke Service.
  6. The client will receive a communication exception because the router tried to route the message to an endpoint that does not exist.

    Figure 36

    The client receives a communication error

Task 3 – Enabling Backup Lists

The router service can establish a backup list for each endpoint that it routes to. In the event that it is unable to communicate to the primary endpoint, it will begin trying the services in the backup list until it successfully invokes a service or all of them fail.

  1. Open the Web.config file from the RouterService project.
  2. Add a backup list in the routing section as shown.

    (Code Snippet - What is new in WCF4 Lab – BackupLists XML)

    Web.config

    <routing>
    <backupLists> <backupList name="backupList1"> <add endpointName="roundingCalculatorEndpoint"/> </backupList> </backupLists>

  3. Filters can have an optional backup list. Modify the XPathFilter that is routing to the badEndpoint and add a backup list as shown.

    XML

    <filterTable name="filterTable1">
    FakePre-734b952e69734cf6aaa527d5c0d46412-6ef3d2a49d6b433b8b7041734682ac0dFakePre-2f50be3be8ac4734bf3cf3a57f802a5d-475c41fba6d24dfab985c9bd895e0dda backupList="backupList1"FakePre-4dc0f25ef85b41bb8e9785288ed57a7b-c06e30910f4e4ca79a75c7d71b819781

Next Step

Exercise 10: Verification