Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to intercept raw soap request/response (data) from WCF client

Tags:

soap

asp.net

wcf

This question seems to be pretty close to what I am looking for - I was able to setup tracing and I am looking at the log entries for my calls to the service.

However I need to see the raw soap request with the data I am sending to the service and I see no way of doing that from the SvcTraceViewer (only log entries are shown but no data sent to the service) - am I just missing configuration?

Here's what I got in my web.config:

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="App_Data/Logs/WCFTrace.svclog"  />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

Any help appreciated!

UPDATE: this is all I see in my trace:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
  <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>262163</EventID>
    <Type>3</Type>
    <SubType Name="Information">0</SubType>
    <Level>8</Level>
    <TimeCreated SystemTime="2010-05-10T13:10:46.6713553Z" />
    <Source Name="System.ServiceModel" />
    <Correlation ActivityID="{00000000-0000-0000-1501-0080000000f6}" />
    <Execution ProcessName="w3wp" ProcessID="3492" ThreadID="23" />
    <Channel />
    <Computer>MY_COMPUTER_NAME</Computer>
  </System>
<ApplicationData>
  <TraceData>
    <DataItem>
      <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
        <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Channels.MessageSent.aspx</TraceIdentifier>
          <Description>Sent a message over a channel.</Description>
            <AppDomain>MY_DOMAIN</AppDomain>
            <Source>System.ServiceModel.Channels.HttpOutput+WebRequestHttpOutput/50416815</Source>
            <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord">
            <MessageProperties>
              <Encoder>text/xml; charset=utf-8</Encoder>
              <AllowOutputBatching>False</AllowOutputBatching>
              <Via>http://xxx.xx.xxx.xxx:9080/MyWebService/myService</Via>
            </MessageProperties>
          <MessageHeaders></MessageHeaders>
        </ExtendedData>
      </TraceRecord>
    </DataItem>
  </TraceData>
</ApplicationData>
like image 818
JohnIdol Avatar asked May 10 '10 12:05

JohnIdol


2 Answers

You don't have a specific tab that shows just the SOAP message - but the XML tab does include the whole SOAP message - no??

alt text

What is missing for you from this snippet of XML here??

UPDATE: John, you're unfortunately not showing what your <system.serviceModel>/<diagnostics> section looks like - mine used for this result looks like this:

<diagnostics>
  <messageLogging 
      logMessagesAtTransportLevel="true" 
      logMessagesAtServiceLevel="false"
      logMalformedMessages="true" 
      logEntireMessage="true"
      maxSizeOfMessageToLog="65535000" 
      maxMessagesToLog="500" />
</diagnostics>

Do you have the same settings? Maybe you're missing logEntireMessage or something else??

like image 179
marc_s Avatar answered Nov 07 '22 14:11

marc_s


I recently encountered the same problem as in the update to the original question: the trace was showing that a message had been sent, but the message itself wasn't there. For me, the fix was to add a System.ServiceModel.MessageLogging source. Here's my system.diagnostics config section:

<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>
   </sources>
   <sharedListeners>
      <add name="xml" 
           type="System.Diagnostics.XmlWriterTraceListener" 
           initializeData="C:\logfiles\Traces.svclog" />
   </sharedListeners>
</system.diagnostics>

And my system.serviceModel / diagnostics section:

<diagnostics>
   <messageLogging
      logMessagesAtTransportLevel="true"
      logMessagesAtServiceLevel="true"
      logMalformedMessages="true"
      logEntireMessage="true"
      maxSizeOfMessageToLog="65535000"
      maxMessagesToLog="500" />
</diagnostics>

Once I added the MessageLogging source, the TraceViewer showed "Message Log Trace" traces which contained the actual SOAP messages.

like image 24
Nick Cecil Avatar answered Nov 07 '22 16:11

Nick Cecil