Gus
Gus

Reputation: 3554

WCF service client: How do I debug the response parsing

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?

Upvotes: 4

Views: 4544

Answers (1)

Anastasiosyal
Anastasiosyal

Reputation: 6626

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

Upvotes: 7

Related Questions