我正在与使用 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;
}
}