This project is read-only.

Pipeline - ending request

Topics: Web Api
Nov 6, 2010 at 1:47 AM


On a processor executing on the request pipeline, is there a way to terminate the request (the operation not being called) and define the contents of the response message?

Apparently, returning a result with Status = ProcessorStatus.Error short-circuits the current pipeline, but the operation is still called.


Pedro Felix

Nov 6, 2010 at 3:40 AM

There isn't in the current bits, but there will be with the next drop. There will be two ways to do it:

The first way is to take in the Response message as in input, set whatever you want on it and then set error.

The second way is you will be able to throw a WebFaultException<HttpResponseMessage> passing in whatever you response you want.

Either case will cause the pipeline to stop and immediately return a response. In the current bits, it doesn't look like that scenario is supported.

Out of curiosity what type of processor are you writing?


Nov 6, 2010 at 3:48 AM

I'm was writing a little processor to extract the IIdentity from the current ServiceSecurityContext and output it as an argument. This way, the operation can have an explicit IIdentity parameter, which facilitates unit testing.

This IIdentity output argument can also feed other downstream processors that use this information (e.g. auditing, authorization) 

What do you think of it?



Nov 6, 2010 at 3:51 AM

You could try this. Pull in the response message and set it. Then two a regular exception. It might work.


Nov 6, 2010 at 10:34 AM

I don't think it works. The exception is caught by the Processor base method, which returns a ProcessorStatus.Error result.

After this, the pipeline ends the processor execution and returns to the formatter, which tries (unsuccessfully) to bind the pipeline results to the operation parameters.


Nov 6, 2010 at 11:14 AM

Was worth a try. It will work though soon.

As far as the approach of using a processor to do method injection to improve testabilty / achieve SOC, I think it is a valid approach (it's something we thought of during design of the processors) The one caveat is it is a bit dry to pass in the params over and over again to each operation which would not be required if there was an Identity service injected in the ctor (something which I hope we support out of the box soon). It does work though.