【问题标题】:SOAP message is empty when catching MessageLoggingTraceRecords with CustomTraceListener使用 CustomTraceListener 捕获 MessageLoggingTraceRecords 时 SOAP 消息为空
【发布时间】:2011-04-27 14:01:41
【问题描述】:

我想编写将所有数据写入 SQL Server DB 的 CustomTraceListener。 这是它的存根:

public class SqlTraceListener : TraceListener 
{
    public SqlTraceListener()
        : base()
    { }

    public SqlTraceListener(String name)
        : base(name)
    { }

    protected override string[] GetSupportedAttributes()
    {
        List<string> attributes = new List<string>();
        attributes.Add("connectionString");
        attributes.Add("actionFilter");
        attributes.Add("hostFilter");
        return base.GetSupportedAttributes();
    }

    public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
    {  }//Other empty methods...

}

在重写的方法 TraceData 中,我想捕获发送到我的 WCF 服务的 SOAP 消息。但是当我检查“数据”参数中的内容时,我得到了这个:(抱歉将 xml 作为图片发布 - 似乎 SO 编辑器不允许在帖子中使用一些 xml 关键字)

但根据标准 XmlWriterTraceListener 我应该得到这个:

如何配置 TraceListener 不消除 SOAP 消息? 我的配置在这里:

  <system.diagnostics>
<sources>
  <source name="System.ServiceModel.MessageLogging">
    <listeners>
      <add name="xml"/>
      <add name="sql"/>
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add initializeData="C:\logs\StockPriceService.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml"/>
  <add type="SqlTraceListener.SqlTraceListener, SqlTraceListener" name="sql"/>
</sharedListeners>
<trace autoflush="true"/>

【问题讨论】:

  • 您找到解决问题的方法了吗?
  • 很遗憾没有。我使用标准的 XmlWriterTraceListener 作为存根有一段时间了。

标签: wcf soap trace tracelistener


【解决方案1】:

您是否有任何理由不使用开箱即用的数据库跟踪侦听器?请参阅:Enterprise Library Database Trace Listener?

【讨论】:

    猜你喜欢
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2023-03-20
    相关资源
    最近更新 更多