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