Debug WCF debugging

How can I register which xml is sent to my WCF REST service before it is deserialized into my datacontract class?

+3
source share
2 answers

You can use WCF tracing to log raw XML messages.

Tracing is not enabled by default. You can enable and configure tracing by editing the application configuration file. The following example .configincludes WCF tracing with raw message logging:

<configuration>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
              logEntireMessage="true"
              logMessagesAtServiceLevel="true"
              logMalformedMessages="true"
              logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.IdentityModel" 
              switchValue="Verbose" 
              logKnownPii="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- ActivityTracing and propogateActivity are used to 
           flesh out the 'Activities' tab in SvcTraceViewer to 
           aid debugging. -->
      <source name="System.ServiceModel" 
              switchValue="Error, ActivityTracing" 
              propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- This records Microsoft.IdentityModel generated traces, 
           including exceptions thrown from the framework. -->
      <source name="Microsoft.IdentityModel" switchValue="Warning">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml" 
           type="System.Diagnostics.XmlWriterTraceListener" 
           initializeData="C:\logs\trace.svclog" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>

Learn more about WCF tracing from MSDN: tracing configuration .

.svclog.

, , initializeData, .

+4

HTTP-, -, Fiddler, . , POST/PUT'd REST.

"", " HTTP- ", , . , " WCF" . .

+1

Source: https://habr.com/ru/post/1729959/


All Articles