This project is read-only.

How to validate parameters with parameter inspectors

J.D. Meier, Jason Taylor, Prashant Bansode, Carlos Farre, Madhu Sundararajan, Steve Gregersen.

Use the following steps to validate parameters with parameter inspectors:
  1. Create a class the implements the parameter validation logic. This class has to inherit from the interface IParameterInspector. The implementation of this interface will allow to do parameter validation both in client and service
  2. Implement the methods AfterCall and BeforeCall** depending if you are validating input or output parameters in client or service. BeforeCall will validate output parameters in client and input parameters in service. AfterCall will validate input parameters in client and output parameters in service.
  3. Create a class that implements a endpoint behavior. This class has to inherit from interface IEndpointBehavior.**
  4. Implement the methods ApplyClientBehavior and ApplyDispatchBehavior depending if you are doing client and/or service side validation. Add the parameter inspectors in with clientOperation.ParameterInspectors.Add in ApplyClientBehavior and/or dispatchOperation.ParameterInspectors.Add in ApplyDispatchBehavior
  5. Create a class that implements custom behavior element. This class has to inherit from BehaviorExtensionElement. This will allow adding the custom behavior to the configuration tool.
  6. Add the Custom Behavior to the Configuration File. Insert the custom extension inside the WCF configuration file, so it can be used by the service
        <add name="Validator" type="MyParamaterValidator. CustomBehaviorSection, MyParamaterValidator, Version=, Culture=neutral, PublicKeyToken=null" />
  1. Create an Endpoint Behavior and Map it to Use the Custom Behavior. This will allow the endpoint behavior to use the schema valiation
        <behavior name="MyEndPointBehavior">
          <Validator />

  1. Configure the Service Endpoint to Use the Endpoint Behavior. This will allow the service endpoint to be configured with the endpoint behavior
<endpoint address="" behaviorConfiguration="MyEndPointBehavior"
          binding="wsHttpBinding" contract="IService">
            <dns value="localhost" />

Last edited May 8, 2008 at 7:19 AM by prashantbansode, version 1


No comments yet.