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
<system.serviceModel>
  ...
    <extensions>
      <behaviorExtensions>
        <add name="Validator" type="MyParamaterValidator. CustomBehaviorSection, MyParamaterValidator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
   </extensions>
 ... 
 <system.serviceModel>
  1. Create an Endpoint Behavior and Map it to Use the Custom Behavior. This will allow the endpoint behavior to use the schema valiation
<behaviors>
...
<endpointBehaviors>
        <behavior name="MyEndPointBehavior">
          <Validator />
        </behavior>
      </endpointBehaviors>
 ...  
 </behaviors>

  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">
          <identity>
            <dns value="localhost" />
          </identity>
</endpoint>

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

Comments

No comments yet.