2

我得到了 WCF REST 服务,我希望记录从该服务接收\发送的每条消息。在我的 app.config 中,我得到了这个配置:

 <system.serviceModel>
  <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
  </system.serviceModel>    
<system.diagnostics>
    <sources>
    <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
            <listeners>
                <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                    <filter type="" />
                </add>
                <add name="ServiceModelMessageLoggingListener">
                    <filter type="" />
                </add>
            </listeners>
        </source>     
    </sources>
    <sharedListeners>
      <add initializeData="logs\\messages.svclog"
              type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
              name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
              <filter type="" />
          </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

我正在为我的服务使用这个绑定

 WebHttpBinding basicWebBinding = new WebHttpBinding
        {
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferSize = int.MaxValue,
            MaxBufferPoolSize = int.MaxValue,
            CloseTimeout = new TimeSpan(0, 3, 0),
            OpenTimeout = new TimeSpan(0, 3, 0),
            ReceiveTimeout = new TimeSpan(0, 3, 0),
            TransferMode = TransferMode.Buffered,
            SendTimeout = new TimeSpan(0, 3, 0),
            WriteEncoding = Encoding.UTF8,
            ReaderQuotas = new XmlDictionaryReaderQuotas()
            {
                MaxStringContentLength = int.MaxValue,     
            }
        };

和这个操作合同(是的,它模拟 aspx 页面)

 [OperationContract(Name = "process.aspx")]
        [WebInvoke(Method = "POST",ResponseFormat = WebMessageFormat.Xml)]
          Stream ProcessRequest(Stream data);

一切似乎都很好,但我看不到任何请求的 POST 数据,例如

<MessageLogTraceRecord>
<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<Connection>keep-alive</Connection>
<Content-Length>123</Content-Length>
<Content-Type>application/x-www-form-urlencoded</Content-Type>
<Accept>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</Accept>
<Accept-Encoding>gzip, deflate</Accept-Encoding>
<Accept-Language>ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3</Accept-Language>
<Host>localhost</Host>
<Referer>http://localhost/...</Referer>
<User-Agent>Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0</User-Agent>
</WebHeaders>
</HttpRequest>
<Binary xmlns=""></Binary>
</MessageLogTraceRecord>

和回应

<MessageLogTraceRecord>
<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<Connection>keep-alive</Connection>
<Content-Length>159</Content-Length>
<Content-Type>application/x-www-form-urlencoded</Content-Type>
<Accept>*/*</Accept>
<Accept-Encoding>gzip, deflate</Accept-Encoding>
<Accept-Language>ru</Accept-Language>
<Host>localhost...</Host>
<User-Agent>agent</User-Agent>
</WebHeaders>
</HttpRequest>... stream ...</MessageLogTraceRecord>

对此的任何帮助都会很好。

4

1 回答 1

0

我的猜测是 POST 数据超过了默认的消息记录长度。

您是否尝试将 maxSizeOfMessageToLog="200000" 添加到 messageLogging 元素?(显然可以根据需要设置大小)

这是我成功使用的设置。

<messageLogging 
logEntireMessage="true" 
logMalformedMessages="false"
logMessagesAtServiceLevel="true" 
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="200000"/>

干杯克里斯

于 2012-11-21T13:31:30.607 回答