Caching and Automatic Help Page

This sample demonstrates the following:

  • How to create a REST service using WCF REST features.

  • How to enable the service to automatically generate a help Web page.

  • How to declaratively specify what caching capabilities you need.

Sample details

Creating a REST Service

The sample demonstrates how to expose a singleton resource by using a WCF REST service that acts as a counter that manages the HTTP verbs.

The sample does the following actions.

  1. Create the counter with an initial value or increment the counter by a specified value by calling HTTP-POST.

  2. Updates the counter value using HTTP-PUT.

  3. Retrieves the counter value by calling HTTP-GET.

  4. Deletes the counter by calling HTTP-DELETE.

The sample also shows how you can get the same resource to return different representations (XML and JSON) based on the URL.

Enabling Automatic Help Page

The sample demonstrates how to automatically enable a help page as an HTML web page for your WCF REST service with a single configuration entry. The help page shows the different URI templates supported, the different request and response formats (XML and JSON are shown) supported, as well as schema and examples of messages in the supported formats.

Declarative Caching

The sample demonstrates how to specify declarative caching using the ASP .NET Output Cache profile mechanism. Specifically, you set an attribute on the method whose response you want to be cached, and refer to an Output Cache profile that you specify in the configuration file. You can also set an attribute to specify whether you want each format to be cached separately.

To use this sample

  1. Using Visual Studio 2010, open the Counter.sln solution file.

  2. To build the solution, press F6.

  3. To run the solution, press CTRL+F5.

    You can also deploy the sample to Internet Information Services (IIS) and invoke it from the browser.

    To see the help page, run the service as previously shown, and then click the .svc file. Suffix the URL in the address bar with /help to see the help page.

Note

The samples may already be installed on your machine. 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\Web\AspNetCachingIntegration

Build Date: 2010-02-04