【问题标题】:WCF - Inspect an MTOM encoded message BeforeSendRequestWCF - 检查 MTOM 编码的消息 BeforeSendRequest
【发布时间】:2012-04-04 23:03:54
【问题描述】:

我正在与使用 Mtom 作为消息编码的第三方 WCF 服务集成。 我已经创建了一个消息检查器行为,并且我可以通过调用request.ToString() 查看消息请求“字符串”,但是,该消息似乎从未经过 mtom 编码,并且不包含任何 MIME 部分。我假设 Mtom 编码稍后发生在通道管道中。我的问题是,有没有办法查看实际的传出消息而不管编码如何,因为它将通过线路发送到 WCF 服务?

下面是我正在使用的消息检查器:

public class InspectorBehaviorExtensionElement : BehaviorExtensionElement
{
    public InspectorBehaviorExtensionElement()
    {

    }

    public override Type BehaviorType
    {
        get
        {
            return typeof(InspectorBehavior);
        }
    }

    protected override object CreateBehavior()
    {
        return new InspectorBehavior();
    }

}

public class InspectorBehavior : IEndpointBehavior
{
    public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
    }

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        clientRuntime.MessageInspectors.Add(new MessageInspector());
    }

    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
    }

    public void Validate(ServiceEndpoint endpoint)
    {
    }
}

public class MessageInspector : IClientMessageInspector
{
    public MessageInspector()
    {

    }
    public void AfterReceiveReply(ref Message reply, object correlationState)
    {
        Debug.WriteLine("Received the following reply: '{0}'", reply);
    }

    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        Debug.WriteLine("Sending the following request: '{0}'", request);

        return null;
    }
}

【问题讨论】:

    标签: wcf wcf-client mtom


    【解决方案1】:

    AFAIK 消息编码在BeforeSendRequest 之后应用。您可以使用 WCF 消息记录或 fiddler 来查看消息。

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 2011-07-31
      • 2011-06-03
      • 1970-01-01
      • 2013-05-10
      • 2013-06-15
      • 1970-01-01
      相关资源
      最近更新 更多