5

我已经通过帮助链接的配置解决了记录用户名和密码的问题

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

但消息正文始终是“......流......”,

有没有办法通过配置或以编程方式解决这个问题?

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


我已经看到了消息头和正文。我的问题是>>>正文总是像“......流......”,我需要真正的内容而不仅仅是“......流......”。


请求消息

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

机器配置

<configuration>
    <system.serviceModel>

            <machineSettings enableLoggingKnownPii="true" />

    </system.serviceModel>

    </configuration>

应用程序配置

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

2 回答 2

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>

编辑 :

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

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

于 2013-06-26T07:24:02.420 回答
0

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

使用 logMessagesAtTransportLevel="true"

    <system.serviceModel>
       <diagnostics>
        <messageLogging 
             logEntireMessage="true" 
             logMalformedMessages="false"
             logMessagesAtServiceLevel="true" 
             logMessagesAtTransportLevel="true"
             maxMessagesToLog="3000"
             maxSizeOfMessageToLog="2000"/>
      </diagnostics>
    </system.serviceModel>
于 2015-11-16T23:09:07.510 回答