How to Validate Outbound Messages on a Service

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

Implement the BeforeSendReply method of the interface IDispatchMessageInspector of the message inspector to validate outbound messages on a service. This allows you to validate the message before sending the response to the client and before service operation invocation and serialization.
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 13, 2008 at 8:10 PM by prashantbansode, version 1

Comments

No comments yet.