Implement BeforeSendReply Method to Validate Outbound Messages on the Service

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

If you need to perform validation on service of outbound messages, implement the BeforeSendReply of the interface IDispatchMessageInspector of the message inspector. This will validate the message before sending the response to the client and the service operation invocation and serialization.

Outbound message validation will be required if you want to validate the message , before sending the response to the client, so you can validate output parameters, message and data contracts.

Following code example shows how to implement the BeforeSendReply method.
void IDispatchMessageInspector.BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
    try
    {
        validateMessage(ref reply);                
    }
    catch (FaultException fault)
    {
        // if a validation error occurred, the message is replaced
        // with the validation fault.
        reply = Message.CreateMessage(reply.Version, new FaultException("validation error in reply message").CreateMessageFault() , reply.Headers.Action);
    }
}

Additional Resources

Last edited Jun 12, 2008 at 10:17 PM by prashantbansode, version 1

Comments

No comments yet.