微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WCF 服务跟踪 - 如何查看服务调用的输入和输出数据?

如何解决WCF 服务跟踪 - 如何查看服务调用的输入和输出数据?

我们最近接管了一个用 WCF 和 C# 编写的 Web 服务应用程序。没有客户端应用程序来测试我的本地机器上的服务。我所能做的就是在 UAT 中打开跟踪。如下图。

<system.diagnostics>
 <sources>
<source name="System.ServiceModel"
        switchValue="information,ActivityTracing"
        propagateActivity="true" >
  <listeners>
    <add name="xml"/>
  </listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
  <listeners>
    <add name="xml"/>
  </listeners>
</source>
<source name="myUserTraceSource"
        switchValue="information,ActivityTracing">
  <listeners>
    <add name="xml"/>
  </listeners>
</source>
  </sources>
  <trace autoflush="true" />
  <sharedListeners>
<add name="xml"
     type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="C:\logs\Traces.svclog" />
 </sharedListeners>
</system.diagnostics>

但是当我使用 Svcutil.exe 打开跟踪文件时,我没有看到任何在系统之间传递的真实数据元素。哪里可以看到数据?还有其他/更好的方法可以在我的本地机器上运行应用程序吗?

解决方法

您可以使用 WCF 测试客户端测试应用程序。 WCF 测试客户端是一个 GUI 工具,允许您向 Web 服务发送请求并查看响应。它会根据服务定义自动生成服务中的方法,因此您无需为此烦恼。

您通常可以在以下位置找到 WCF 测试客户端 (WcfTestClient.exe):C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE - 社区可能是“企业”之一、“专业”或“社区”取决于安装的 Visual Studio 的级别。

欲了解更多信息,请访问:https://docs.microsoft.com/en-us/dotnet/framework/wcf/wcf-test-client-wcftestclient-exe

,

您缺少在 serviceModel 配置中启用 messagelogging 的位。

将此添加到您的 web.config / app.config 中的 system.serviceModel 配置部分:

<system.serviceModel>  
    <diagnostics>  
      <messageLogging logEntireMessage="true"  
                      maxMessagesToLog="3000"  
                      maxSizeOfMessageToLog="20000"
                      logMessagesAtServiceLevel="true"  
                      logMalformedMessages="true"  
                      logMessagesAtTransportLevel="true" />  
    </diagnostics>  
    <!-- your bindings / services / behaviors are here --> 
</system.serviceModel> 

还将您的开关值设置为 Verbose

<source name="System.ServiceModel.MessageLogging"
        switchValue="Verbose">
  <listeners>
    <add name="xml"/>
  </listeners>
</source>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。