The .NET Endpoint

Blog by the .NET and AppFabric teams about WCF and WF development, deployment, and management

Monitoring WCF Data Services with Windows Server AppFabric

Monitoring WCF Data Services with Windows Server AppFabric

  • Comments 4

WCF Data Services provides a very simple model driven way to expose data using REST and the OData format.  As I was preparing my talk for Tech-Ed on Implementing REST in .NET I was asking myself if there would be any value in using Windows Server AppFabric with WCF Data Services.  After all, AppFabric has monitoring which can capture tracking information across the server farm storing it in a monitoring database.  Typically we show Workflow Services using this capability because they provide such a rich stream of tracking events. However, it is quite possible to use AppFabric to monitor data services.  In this post I’ll take you through step by step how you can do it.

Note: To make this post more readable – click on the images to see them full size. The team also has a sample on this here

Step 1 – Host your site in IIS

To benefit from Windows Server AppFabric your web application must be hosted in IIS.  To use Visual Studio with IIS you must run it as administrator.  Then go into the project properties of your web application and set it to run in the local IIS server.

image

Step 2 – Browse to your service and see the monitoring in action

In my RESTWeb demo application I’ve added some links to the Default.htm page that will exercise the service.  If you run the app and hit a few pages you will see that AppFabric captures information about your service being invoked. 

To see it

  1. Open IIS Manager
  2. Select the RESTWeb website by expanding the Default Web site
  3. Double click on AppFabric Dashboard
  4. Check the WCF Call History section

image

Here you can see that there were 4 calls to the WCF Data Service named Conference.svc.  If you click on the hyperlink for Conference.svc you will get the detail on those 4 calls.

image

This is good, but because we have a WCF Data Service all the requests look the same in the tracking data.  We can see that somebody invoked the service but we don’t know what things they were querying in the model or if they were doing a GET, POST, PUT etc. 

Step 3 – Instrument your service to emit custom tracking records

In my RESTWeb web application, I’ve added some sample code I got from the AppFabric guys (with some minor modifications from me) that shows how you can emit a custom tracking record that will be displayed in AppFabric.  By overriding the DataService.OnStartProcessingRequest method, I can now emit a tracking record with details of the request.

    public class Conference : DataService<ConferenceDataEntities>
    {
        // Sample class allows you to emit custom tracking records
        static WCFUserEventProvider eventProvider = new WCFUserEventProvider();

        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            string text = string.Format("Processing HTTP {0} request for URI {1}", 
                args.OperationContext.RequestMethod, args.RequestUri);

            // Push the event through ETW to AppFabric
            eventProvider.WriteInformationEvent("Conference Request", text);
        }

Step 4 - Enable End-To-End Tracking

To make this work you have to turn on end-to-end tracking in AppFabric.  To do this

  1. Right click on your web app and select Manage WF and WCF Services
    image
  2. Select the Monitoring Tab
  3. Set the monitoring level to End-To-End
    SNAGHTML42dfda5

 

Step 5 – Verify Behavior

  1. Run a few more queries through your data service. In my RESTweb example just click through a few links on the home page.
    image
  2. Open (or refresh) AppFabric Dashboard as you did before.
  3. Click the link for calls to Conference.svc
  4. Right click on the top event and select View Related Events
    image
  5. Now you will see a number of related events (related because of end-to-end tracking) – the tracking record payload will contain the message we created in the code.
    SNAGHTML43491b9[4]

Summary

The attached sample code is what I showed at my Tech-Ed Session.  Hope you find it helpful.

Attachment: RESTWeb.zip
  • Hi Ron, excelent post.

    I have a question for you, how can I filter the events using the tracked information as a filter?

    Using your example, something like: Payload = 'filter value'

    Thanks in advance...

  • The tracked events are stored in a database so you can query filter or do whatever you want with them.

  • Ron, thanks for your reply.

    I understand you, but I want to use the user interface of AppFabric, but i think that is not possible to do.

    Let me explain my idea, I want to implement an extension to the AppFabric's monitoring, the new functionality let you define  "promoted fields" from request and response messages in a WCF service(this fields will be tracked), and I want to be able to query using this information in the same way that AppFabric filters using tracked WF variables.

    As I can see, I need to extended AppFabric's UI  too, maybe with a new IIS module

    What do you think about?

  • Yes you can create an IIS Module and then show whatever you want in the UI.  It isn't possible to extend the existing module

Page 1 of 1 (4 items)