This project is read-only.

How to Validate Parameters with Parameter Inspectors

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

Use the following steps to validate parameters with parameter inspectors:
  1. Create a Class That Implements the Validation Logic. This class has to derive from IParameterInspector. In the class you will have the following characteristics:
  2. It implements AfterCall() and BeforeCall() methods. Those methods will have the validation logic.
  3. When used as part of the service, BeforeCall() will be invoked before the parameters are dispatched to the service operation. AfterCall() will be invoked after the service has processed the call and is returning a the response to the client. Use BeforeCall() to validate your input parameters and AfterCall() to validate your output parameters.
  4. When used as part of the client, BeforeCall() will be invoked before calling the service, and AfterCall() before the service’s response is dispatched to the client code. Use AfterCall() to validate the response from the service, and BeforeCall() to validate the return from the service
  5. Create a Class That Implements a Custom Endpoint Behavior. This class derives from IEndpointBehavior that the service and / or client endpoint will use as a configuration extensibility point for the endpoint. This class has the following characteristics
  6. It implements ApplyClientBehavior() to add the ParamaterInspector to the client operation and enable client-side validation.
  7. It implements ApplyDispatchBehavior() toadd the ParameterInspector to the dispatch operation and enable service-side validation.
  8. It verifies that it is enabled in the configuration before adding the ParameterInspector to the client or dispatch run time.
  9. Create a Class That Implements a Custom Configuration Element. This class derives from BehaviorExtensionElement, This class allows to expose the endpoint configuration in WCF as a behavior element extension, that can be used by the service as an endpoint behavior configuration. This class has the e following characteristics:
  10. It implements CreateBehavior() to create an instance of the ValidationBehavior class.
  11. It implements BehaviorType() to return the ValidationBehavior type. This will allow the custom behavior to be exposed in the service or client configuration sections.
  12. Add the Custom Behavior to the Configuration File . You will add the custom behavior element to the behavior element extension items, so it can be used by the endpoint behavior. You add it in the configuration file with the configuration tool, by browsing to the assembly, and selecting the type that is your custom behavior type.
  13. Create an Endpoint Behavior and Map It to Use the Custom Behavior. You will create a endpoint behavior to use the custom behavior extensible point provided by your assembly implementing the parameter inspector
  14. Configure the Service Endpoint to Use the Endpoint Behavior. You will configure the endpoint to use the endpoint behavior that is using the parameter inspector.

Additional Resources

Last edited Jun 13, 2008 at 9:07 PM by prashantbansode, version 1


No comments yet.