How to validate outbound messages on a service

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

Implement the BeforeSendReply 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);
    }
}

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

Comments

No comments yet.