wcf .svclog文件中的所有消息体总是“<env:body> ... stream ... </env:body>”,如何通过配置显示真实内容?

时间:2013-06-26 06:31:13

标签: wcf

我已通过配置帮助链接

解决了日志用户名和密码问题

邮件记录的安全问题 http://msdn.microsoft.com/en-us/library/ms730318.aspx

但是邮件正文总是“... stream ...”,

有什么方法可以通过配置来解决这个问题,还是以编程方式来解决这个问题?

我只是想看看使用SvcTraceViewer工具“请求/响应详细的soap xml”。


我已经看到邮件标题和body.my问题都是&gt;&gt;&gt; 身体总是像“...流...”,我需要真正的内容而不仅仅是“......流......”。


请求消息

<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>

响应消息(“env:Body”标签中的问题)

<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>

2 个答案:

答案 0 :(得分:4)

是的,WCF跟踪默认情况下不会记录整个邮件(只有soap标头)

配置WCF跟踪有很多选项。

logEntireMessage :指定是否记录整个邮件(邮件标题和正文)。默认值为false,表示仅记录标头。

maxMessagesToLog :指定要记录的最大消息数。达到配额时,将发出跟踪并且不会记录其他消息。默认值为10000。

maxSizeOfMessageToLog :指定要以字节为单位记录的消息的最大大小。不记录超出大小限制的邮件。服务级别和传输级别消息的默认值为256K,而格式错误的消息的默认值为4K。

非常基本的配置是

<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>

修改:

你在使用Streaming吗?在流式消息上,仅记录标头。你无法改变这一点。为了查看正文内容,您唯一的选择是禁用流媒体。

将绑定配置(服务和客户端)中的 TransferMode 属性更改为缓冲

答案 1 :(得分:0)

可以选择记录... stream ...邮件正文。在服务级别,不记录流,但在传输中可以记录整个正文。

使用logMessagesAtTransportLevel =&#34; true&#34;

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