This project is read-only.

If you need to do schema validation, use message inspectors

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

Use Message Inspectors to inspect the messages flowing in and out of a service regardless of the operation. Message inspection is one of the extensibility points that allows you to customize the runtime behavior for service dispatching and client proxy invocation.

To use message inspection both at the dispatcher and at the proxy, implement the interfaces IDispatchMessageInspector and IClientMessageInspector. The IDispatchMessageInspector interface has two methods, AfterReceiveRequest and BeforeSendReply, which means that you get pre and post-interception points for inspecting the WCF Message object. The AfterReceiveRequest correspond to the BeforeDeserialize message state i.e., the request before going through the XML serializer and the BeforeSendReply correspond to the AfterSerialize message state i.e., the response after going through the XML serializer.

Example
public class ConsoleMessageTracer : IDispatchMessageInspector, 
    IClientMessageInspector
{
    
    public object AfterReceiveRequest(ref Message request, 
        IClientChannel channel, 
        InstanceContext instanceContext)
    {
	  //do some impelmentation
        return null;
    }
    public void BeforeSendReply(ref Message reply, object
        correlationState)
    {
	  //do some impelmentation
    }

    public void AfterReceiveReply(ref Message reply, object
        correlationState)
    {
	  //do some impelmentation
    }
    public object BeforeSendRequest(ref Message request, 
        IClientChannel channel)
    {

	  //do some impelmentation
        return null;
    }
}

Last edited Apr 17, 2008 at 12:46 AM by prashantbansode, version 1

Comments

No comments yet.