2012-11-21 92 views
2

我得到了WCF REST服務,並且希望從此服務發送的每個消息都被記錄。使用我的服務WCF REST消息日誌記錄,POST請求問題

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

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

我真的:在我的app.config我得到這個配置

Everythig似乎很好,但我不能看到任何請求的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> 

任何幫助,在此將是很好。

回答

0

我的猜測是POST數據超過了默認的消息記錄長度。

您是否嘗試將maxSizeOfMessageToLog =「200000」添加到messageLogging元素中? (顯然你可以根據需要設置大小)

這裏是我成功使用的設置。

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

乾杯 克里斯

+0

我覺得把它添加到Windows事件日誌條目如果消息大小的問題。 –

+0

不幸的是,設置maxSizeOfMessageToLog並沒有解決這個問題,我仍然在請求中獲得,並且logMessagesAtTransportLevel =「false」: ... stream ...作爲迴應 – Yaroslav

+0

流是否可以通過反序列化嗎?我認爲這是來自內容類型判斷的表單發佈? –