使用参数信息记录WCF服务调用

Mar*_*son 13 .net wcf logging

我一直在使用服务跟踪查看器来分析在我们的应用程序中进行的WCF服务调用,但我真的需要查看传递给服务方法的参数值吗?这可能吗?我已经尝试将记录转为最大输出,但仍然看不到任何东西:(

mar*_*c_s 18

如果启用了消息跟踪,则应获取该调用的所有详细信息(包括发送消息的XML表示形式)以及答案:

<system.diagnostics >
  <sources>
    <source  
        name="System.ServiceModel.MessageLogging" 
        switchValue="Information, ActivityTracing" >
       <listeners>
          <add name="yourTrace" 
               type="System.Diagnostics.XmlWriterTraceListener" 
               initializeData="C:\Logs\YourMessageLog.svclog">
             <filter type="" />
           </add>
       </listeners>
     </source>
  </sources>
  <trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
   <diagnostics>
       <messageLogging 
             logMessagesAtTransportLevel="true" 
             logMessagesAtServiceLevel="false"
             logMalformedMessages="true" 
             logEntireMessage="true"
             maxSizeOfMessageToLog="65535000" maxMessagesToLog="500" />
    </diagnostics>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

这应该在目录"C:\ Logs"(必须事先存在!)中创建一个名为"YourMessageLog.svclog"的文件,并且可以使用WCF服务跟踪查看器查看该文件.

你会在这里看到的是消息的XML表示和返回的响应 - 你的参数将被包装到你的XML结构中.这就是你要找的东西吗?