WCF 服务客户端:如何调试响应解析

发布于 2024-12-22 20:42:05 字数 1514 浏览 1 评论 0原文

我正在构建一个 Web 服务客户端来与(基于 Java 的)远程 Web 服务交互,这是我无法控制的。我可以调用 Web 服务操作,并且可以通过数据包嗅探得知该服务正在使用填充的数据进行响应。然而,当响应进入客户端代码时,响应只是一个外壳,所有数据均为空。

我怀疑 Web 服务“管道”中发生错误,导致数据被默默删除或忽略,但我找不到在接收期间启用调试(甚至日志或错误消息?)的方法在到达我的客户端代码之前的响应。

我的 App.config 启用了消息记录,但只记录传出消息:

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="messages"
                type="System.Diagnostics.XmlWriterTraceListener"  
                initializeData="c:\messages.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

<system.serviceModel>
    <diagnostics>
        <messageLogging
             logEntireMessage="true"
             logMalformedMessages="true"
             logMessagesAtServiceLevel="true"
             logMessagesAtTransportLevel="true"
             maxMessagesToLog="3000"
             maxSizeOfMessageToLog="2000"/>
    </diagnostics>
</system.serviceModel>

我真的想在实际解析响应消息期间设置断点,但让消息记录器实际记录响应也可能会有所帮助。

我还配置了一个自定义 MessageEncoder ,这是解决远程服务解析器中的错误所必需的。我可以向该 MessageEncoder 上的 ReadMessage 方法添加断点,并且可以看到此时数据仍然存在。然而,下一步跳回到客户端代码,并且 Response 对象是空的——没有警告或消息。有什么办法可以看到这之间发生了什么吗?

所以,我想这最终是一个由两部分组成的问题:

  1. 如何/在哪里设置断点来观察 SOAP 消息的获取 在 MessageEncoder 之后、但在发送到客户端代码之前进行处理?
  2. 我的日志配置有什么问题,只能传出 消息已记录?

I am building a web service client to interact with a (java-based) remote web service, out of my control. I can call the web service operation, and can tell by packet-sniffing that the service is responding with populated data. However, by the time that response makes it into the client code, the response is only a shell, with all the data null.

I suspect that an error is occurring in the web service "plumbing" that is causing the data to be silently dropped or ignored, but I can't find a way to enable debugging (or even logs or error messages?) during the receipt of the response before it hits my client code.

My App.config has Message Logging enabled, but only outgoing messages are being logged:

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="messages"
                type="System.Diagnostics.XmlWriterTraceListener"  
                initializeData="c:\messages.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

<system.serviceModel>
    <diagnostics>
        <messageLogging
             logEntireMessage="true"
             logMalformedMessages="true"
             logMessagesAtServiceLevel="true"
             logMessagesAtTransportLevel="true"
             maxMessagesToLog="3000"
             maxSizeOfMessageToLog="2000"/>
    </diagnostics>
</system.serviceModel>

I really want to set a breakpoint during the actual parsing of the response message, but having the Message Logger actually log the response may also help a bit.

I've also configured a custom MessageEncoder which was necessary to work around a bug in the remote service's parser. I can add breakpoints to the ReadMessage methods on that MessageEncoder, and can see that the data is still there at that point. However, the next step jumps back into the client code, and the Response object is empty -- no warnings or messages. Is there any way to see what's going on in between?

So, I guess this ends up being a two-part question:

  1. How/Where can I set a breakpoint to observe the SOAP message getting
    processed, after the MessageEncoder, but before it is sent to the client code?
  2. What's wrong with my logging config that only outgoing
    messages are logged?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2024-12-29 20:42:05

以下是如何让响应跟踪为您服务:

1.配置

<system.diagnostics>
<sharedListeners>
  <add name="sharedListener"
       type="System.Diagnostics.XmlWriterTraceListener"
       initializeData="C:\LogFiles\messages.svclog" />
</sharedListeners>
<sources>
  <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >
    <listeners>
      <add name="sharedListener" />
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
    <listeners>
      <add name="sharedListener" />
    </listeners>
  </source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics performanceCounters="All" wmiProviderEnabled="True">
  <messageLogging
       logEntireMessage="True"
       logMalformedMessages="True"
       logMessagesAtServiceLevel="True"
       logMessagesAtTransportLevel="True"
       maxMessagesToLog="3000"
       maxSizeOfMessageToLog="30000"/>
</diagnostics>
</system.serviceModel>

这位于配置节点下的 app.config / web.config 中。

2.查找响应

要快速验证您是否确实收到来自远程服务的服务响应,请在 Visual Studio 中以 xml 文件形式打开日志文件,然后搜索

Source="TransportReceive"< /code>

您应该能够看到远程服务在此 MessageLogTraceRecord 节点中响应了什么。

3.工具

用于查看这些消息的推荐工具是 SvcTraceViewer.exe

您应该能够在以下任一位置找到该工具:

C:\Program Files\Microsoft SDKs\Windows\v6.0A \Bin\x64

C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin

如果您没有此工具,您可以在 Windows SDK

Here is how you can get the response tracing to work for you:

1. Configuration

<system.diagnostics>
<sharedListeners>
  <add name="sharedListener"
       type="System.Diagnostics.XmlWriterTraceListener"
       initializeData="C:\LogFiles\messages.svclog" />
</sharedListeners>
<sources>
  <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >
    <listeners>
      <add name="sharedListener" />
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
    <listeners>
      <add name="sharedListener" />
    </listeners>
  </source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics performanceCounters="All" wmiProviderEnabled="True">
  <messageLogging
       logEntireMessage="True"
       logMalformedMessages="True"
       logMessagesAtServiceLevel="True"
       logMessagesAtTransportLevel="True"
       maxMessagesToLog="3000"
       maxSizeOfMessageToLog="30000"/>
</diagnostics>
</system.serviceModel>

This goes in your app.config / web.config under the configuration node.

2. Locating the Response

A quick validation to see that you actually receive service responses from the remote service is to open up the log file as an xml file in Visual studio and do a search for

Source="TransportReceive"

you should be able to see what the remote service has responded with within this MessageLogTraceRecord node.

3. Tooling

The recommended tool for viewing these messages is SvcTraceViewer.exe

You should be able to find this in either:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64

or

C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin

If you do not have this tool, you can find it in the Windows Sdk

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文