Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wcf all message body in .svclog file always be "<env:Body>... stream ...</env:Body>" , how to show the real content through configuration?

Tags:

wcf

I have solved logging username and password through configuration with the help link

Security Concerns for Message Logging http://msdn.microsoft.com/en-us/library/ms730318.aspx

but the message body always be "... stream ...",

is there any way to solve this through configuration or do it programaticly?

i just want to see "request/responce detailed soap xml" with SvcTraceViewer tool.


i have already seen both message header and body.my problem is that >>> the body is always like "... stream ..." ,i need the real content not just "... stream ...".


request message

<MessageLogTraceRecord>
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
    <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.onvif.org/ver10/device/wsdl/GetSystemDateAndTime</Action>
    <ActivityId CorrelationId="fcc87310-055d-452b-9c0d-ffe671585392" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">4876b839-30d4-4351-abb8-4fa6bf53d7e1</ActivityId>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink"></VsDebuggerCausalityData>
    <Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <UsernameToken>
    <Username>duwu891229</Username>
    <Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">1ax8Hp9OY1H+vw7+w0fv8BDps9M=</Password>
    <Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">V5x7WKzZ4U2DdM9cxhVXuQEAAAAAAA==</Nonce>
    <Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2013-06-26T05:50:06.006Z</Created>
    </UsernameToken>
    </Security>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"></GetSystemDateAndTime>
    </s:Body>
    </s:Envelope>
    </MessageLogTraceRecord>

response message (problem in the "env:Body" tag )

<MessageLogTraceRecord>
    <HttpResponse xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
    <StatusCode>OK</StatusCode>
    <StatusDescription>OK</StatusDescription>
    <WebHeaders>
    <Date>Wed, 26 Jun 2013 13:50:06 GMT</Date>
    <Server>App-webs/</Server>
    <Connection>close</Connection>
    <Content-Length>2406</Content-Length>
    <Content-Type>application/soap+xml; charset=utf-8</Content-Type>
    </WebHeaders>
    </HttpResponse>
    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12" xmlns:http="http://schemas.xmlsoap.org/wsdl/http" xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2" xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2" xmlns:tnshik="http://www.hikvision.com/2011/event/topics">
    <env:Header></env:Header>
    <env:Body>... stream ...</env:Body>
    </env:Envelope>
    </MessageLogTraceRecord>

machine.config

<configuration>
    <system.serviceModel>

            <machineSettings enableLoggingKnownPii="true" />

    </system.serviceModel>

    </configuration>

app.config

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Information, ActivityTracing"
              logKnownPii="true">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="All">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
    </sources>

    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="log\wcf.svclog" />
    </sharedListeners>

    <trace autoflush="true" indentsize="2">
      <listeners>
        <!--<clear />-->
        <add type="System.Diagnostics.ConsoleTraceListener" name="console"/>
      </listeners>
    </trace>

  </system.diagnostics>


  <system.serviceModel>

    <diagnostics wmiProviderEnabled="true">
      <messageLogging logEntireMessage="true" logKnownPii="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
        maxMessagesToLog="3000" />
    </diagnostics>
  </system.serviceModel>
like image 594
user2522745 Avatar asked Oct 04 '22 17:10

user2522745


1 Answers

Yes, WCF tracing does not log entire messages by default (only soap header)

There are many options to configure WCF tracing.

logEntireMessage : specifies whether the entire message (message header and body) is logged. The default value is false, meaning that only the header is logged.

maxMessagesToLog : specifies the maximum number of messages to log. When the quota is reached, a trace is emitted and no additional message is logged. The default value is 10000.

maxSizeOfMessageToLog : specifies the maximum size of messages to log in bytes. Messages that exceed the size limit are not logged. The default value for service level and transport level messages is 256K, while the default value for malformed messages is 4K.

A very basic configuration is

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

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

Edit :

Are you using Streaming ? On streamed messages, only the headers are logged. You can't change this. In order to view body content, your only option is too disable streaming.

Change the TransferMode property in your binding configuraiton (service & client) to Buffered.

like image 58
Cybermaxs Avatar answered Oct 08 '22 03:10

Cybermaxs