This is a mirror of official site: http://jasper-net.blogspot.com/

WCF Data Services Processing Pipeline

| Tuesday, May 3, 2011
First I must confess. Even tough I like OData and WCF Data Services, in the last couple of months I didn’t have the chance to work or use them. This is why when .NET 4 was shipped I haven’t noticed a new and interesting extension point in the framework – the processing pipeline. In the last MIX11 I got a little introduction to that extension point in Mike Flasko’s session. In this post I’ll explain what is the WCF Data Services' server side processing pipeline.

WCF Data Services Processing Pipeline

In the past I wrote about the Interceptions mechanism that is built inside WCF Data Services. One of the advantages of using that mechanism is the ability to wire up business logic such as custom validations, access policy logic or whatever you like to insert in the queries/change sets pipeline. The problem starts when you need a generic behavior for all the entity sets interceptions. In the first release of WCF Data Services there were no extension points to use that will help implement generic things. But now, in .NET4, you can use the processing pipeline in order to do that. The new DataServiceProcessingPipeline is a class that is being used as a property of the DataService class (which every data service inherits from). It exposes four events that you can hook to:

ProcessingRequest – The event occurs before a request to the data service is processed.
ProcessingChangeset – The event occurs before a change set request to the data service is processed.
ProcessedRequest – The event occurs after a request to the data service has been processed.
ProcessedChangeset – The event occurs after a change set request to the data service has been processed.
These events enables the developer to write code that is performed during the process of WCF Data Services pipeline before and after things happen.

Using WCF Data Services Processing Pipeline

Here is a simple example of how to use the processing pipeline events to write to the output window that the events were called: 

public class SchoolDataService : DataService<SchoolEntities>
{
  public SchoolDataService()
  {
    ProcessingPipeline.ProcessedChangeset += new EventHandler<EventArgs>(ProcessingPipeline_ProcessedChangeset);
    ProcessingPipeline.ProcessedRequest += new EventHandler<DataServiceProcessingPipelineEventArgs>(ProcessingPipeline_ProcessedRequest);
    ProcessingPipeline.ProcessingChangeset += new EventHandler<EventArgs>(ProcessingPipeline_ProcessingChangeset);
    ProcessingPipeline.ProcessingRequest += new EventHandler<DataServiceProcessingPipelineEventArgs>(ProcessingPipeline_ProcessingRequest);
  }

Read more: Gil Fink on .Net

Posted via email from Jasper-net

0 comments: