2012-04-04 57 views
0

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

以下为消息检查我正在使用:

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; 
    } 
} 

回答

1

AFAIK邮件编码BeforeSendRequest之后施加。您可以使用WCF消息日志记录或提琴手来查看消息。