Validating WCF response message

Topics: Validation Application Block
Dec 20, 2010 at 5:42 AM

The MSDN article ( on VAB integrating with WCF says in the 2nd paragraph:

When the WCF service begins, it invokes the custom behavior. This custom behavior then adds the parameter inspector. WCF calls the parameter inspector twice for each message it processes. The first time is before it sends the call to the service implementation. The second time is after the service generates the return message.

The last sentence appears to say that I should be able to get validation on the response message of a service operation. I am using a [ValidationBehavior] attribute on the service contract, plus a fault contract for ValidationFault on each operation, and validator attributes on the public properties of the request and response message types (simple data transfer objects). In testing, I get validation faults from validators on the request message, but not from validators on the response message.

Does anyone have any clues, examples, or insights?

My scenario is in contract-first service development, where I only “own” the contract and not the implementations, and I want to verify that each service implementation satisfied validation constraints on the response message.

Dec 20, 2010 at 7:12 AM

I have a small solution that reproduces the problem if you'd like. How should I share that?

Dec 20, 2010 at 7:58 AM

VAB integration with WCF doesn't support validation of return values, it only validates inputs.   The statement from the documentation is true, the parameter inspector is called twice but if you look into the source code, the AfterCall method of the ValidationParameterInspector doesn't contain any logic:

 public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
            // Deliberate noop - we don't need to do anything after the call


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.

Dec 20, 2010 at 5:03 PM

If that is the case, then I am profoundly baffled why that statement is included (prominently) in the documentation. The fact that it is true provides no value to the developer or the client software that I can discern. Developers should not have to resort to reading the source code to figure this out that this statement is without benefit.

But that did waste several hours of my time trying to figure this out. I am not very happy about that.

Stuart Celarier
Microsoft Regional Director
Microsoft MVP, Connected Systems

Dec 21, 2010 at 2:05 AM

Hi Stuart,

Sorry for the inconvenience, what we can suggest for now is you can log a feature request regarding this in the Issue tracker.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.