I’m a big fan of services. It really helps a loosely coupled design.
A WCF DataService isa RESTful service. This means that data can be get, modified or deleted based on the HTTP method used.

  • A GET request will return data
  • A POST request will insert data
  • A PUT request will update data
  • A DELETE request will delete data

It supports many data types (like SOAP, JSON, XML) without any extra programming. This makes it very flexible.

I was experimenting with a DataService and was trying to figure out how I can intercept a request and filter the results before returning the dataset.
In the example below, I am filtering a request for Participants. I only want to show participants with a specific Status.

public class ParticipantService : DataService
   // This method is called only once to initialize service-wide policies.
   public static void InitializeService(DataServiceConfiguration config)
       config.SetEntitySetAccessRule("Participants", EntitySetRights.AllRead);

   public Expression<Func<Participant, bool>> FilterOnActiveStatus()
       return participant => participant.Status == 2;

The QueryInterceptor Attribute intercepts the request for “Participants” and it allows us to return an expression which filters the resultset.