How to Validate Messages with Message Inspectors Using Schemas

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

Use the followings steps to validate using message inspectors and schemas:
  1. Create a Class That Implements the Validation Logic. This class has to derive from IClientMessageInspector,IDispatchMessageInspector depending if you want to do client side and / or server side validation. This calls implements AftterReceiveRequest(),BeforeSendReply(), BeforeSendRequest() and AfterReceiveReply() methods. This class has the following characteristics
  2. On the dispatcher: AfterReceiveRequest will happen when inbound messages are received by the dispatcher, before the operation is invoked and deserialization of messages has occurred. If message is encrypted, decryption will take place first. BeforeSendReply will happen when outbound messages are to be sent back to the client. It will happen after operation is invoked, and after serialization has occurred. If message is encrypted, encryption will not take place.
  3. On the client: BeforeSendRequest will happen when outbound messages are sent by the client, after serialization has occurred. If message is encrypted, encryption will not take place. AfterReceiveReply will happen when inbound messages are received by the client before deserialization of message has occurred. If message is encrypted, decryption will take place first.
  4. 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
  5. It implements ApplyClientBehavior() to add the ParamaterInspector to the client operation and enable client-side validation.
  6. It implements ApplyDispatchBehavior() toadd the ParameterInspector to the dispatch operation and enable service-side validation.
  7. It verifies that it is enabled in the configuration before adding the ParameterInspector to the client or dispatch run time.
  8. 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:
  9. It implements CreateBehavior() to create an instance of the ValidationBehavior class.
  10. It implements BehaviorType() to return the ValidationBehavior type. This will allow the custom behavior to be exposed in the service or client configuration sections.
  11. 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.
  12. 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 message inspector
  13. Configure the Service Endpoint to Use the Endpoint Behavior. You will configure the endpoint to use the endpoint behavior that is using the message inspector.

Additional Resources

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

Comments

No comments yet.