【问题标题】:WCF Service Trace - How to see the input and out data for a service call?WCF 服务跟踪 - 如何查看服务调用的输入和输出数据?
【发布时间】:2021-07-30 02:47:12
【问题描述】:

我们最近接手了一个用 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 打开跟踪文件时,我看不到任何在系统之间传递的真实数据元素。我在哪里可以看到数据?还有其他/更好的方法可以在我的本地机器上运行应用程序吗?

【问题讨论】:

    标签: c# wcf svcutil.exe


    【解决方案1】:

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

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

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

    【讨论】:

    • 在 WCF 测试客户端中,它要求我分别输入每个对象,并且我的 XML 输入非常大。有什么方法可以输入 XML 数据并在客户端中填充数据?
    • 您只需将 WCF 测试客户端指向服务端点,它就会从服务定义中自动为您生成方法。例如,如果您添加此服务:learnwebservices.com/services/hello?WSDL,它将使用两种方法自动生成 Web 服务。您仍然必须一一添加所有端点。据我所知,无法一次在 WCF 测试客户端中添加所有端点。
    • 您还可以通过在解决方案资源管理器中将其设置为启动项目并按 f5 来运行和调试应用程序。 Visual Studio 将使用生成的服务方法自动启动 WCF 测试客户端。
    【解决方案2】:

    您缺少在 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多