WCF REST 调试

标签 wcf debugging serialization

在反序列化到我的数据契约(Contract)类之前,如何记录发送到我的 WCF REST 服务的 xml?

最佳答案

您可以使用 WCF 跟踪来记录原始 XML 消息。

默认情况下不启用跟踪。您可以通过编辑应用程序的配置文件来启用和配置跟踪。以下 .config 示例使用原始消息日志记录启用 WCF 跟踪:

<configuration>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
              logEntireMessage="true"
              logMessagesAtServiceLevel="true"
              logMalformedMessages="true"
              logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.IdentityModel" 
              switchValue="Verbose" 
              logKnownPii="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- ActivityTracing and propogateActivity are used to 
           flesh out the 'Activities' tab in SvcTraceViewer to 
           aid debugging. -->
      <source name="System.ServiceModel" 
              switchValue="Error, ActivityTracing" 
              propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- This records Microsoft.IdentityModel generated traces, 
           including exceptions thrown from the framework. -->
      <source name="Microsoft.IdentityModel" switchValue="Warning">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml" 
           type="System.Diagnostics.XmlWriterTraceListener" 
           initializeData="C:\logs\trace.svclog" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>

您可以从 MSDN: Configuring Tracing 中阅读有关 WCF 跟踪的更多信息.

Microsoft 提供了一个 Service Trace Viewer Tool读取 .svclog 文件。

确保 initializeData 中定义的路径可由您的服务写入。

关于WCF REST 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2135238/

相关文章:

java kryo 3.0.3 对象的序列化速度较低

generics - 用 Jackson 序列化 Map<Date, String>

wcf - 配置 IIS Express 8 以启用 CORS

c# - WCF 中的 WSDL URI 是什么?

python - Selenium 无法通过 Xpath 查找元素?

node.js - 在 VIM 中调试 Nodejs V8

c# - 在断言失败时中断调试器

python - 如何将非常大的数组保存到磁盘?

wcf - SoapUI WCF 使用 SSL 证书

wcf - 如何禁用 WCF 测试客户端 - VS 2012