WCF Validation Messages

I am trying to implement a simple message inspector that writes a message to a debug window from an example on MSDN :

public class MyMessageInspector : IDispatchMessageInspector
{
    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
    {
        System.Diagnostics.Debug.WriteLine(request.ToString());
        return null;
    }

    public void BeforeSendReply(ref Message reply, object correlationState)
    {
        System.Diagnostics.Debug.WriteLine(reply.ToString());
    }
}

The response is recorded as expected. However, the request seems to be null. Any ideas on what could go wrong? I am using a Service Reference proxy with a console application as a client.

I am using basicHttpbinding and hosting with IIS with an svc file. The parameter for my web method is a complex type. I'm not sure if that matters.

+3
source share
2 answers

First, try CreateBufferedCopy (i.e. a clone) of the message request: http://msdn.microsoft.com/en-us/library/ms734675.aspx (Copy message to clipboard).

" ": http://binarymist.net/2010/06/14/message-inspection-in-wcf/

+1

MyMessageInspector -, - - SOAP XML.

- MessageInspectors ? , , request = null - , ref.

, , null? NullReferenceException Debug.WriteLine(..)?

0

Source: https://habr.com/ru/post/1783285/


All Articles