Asp.net

如何攔截來自 WCF 客戶端的原始肥皂請求/響應(數據)

  • July 25, 2019

這個問題似乎與我正在尋找的非常接近——我能夠設置跟踪,並且正在查看我對服務的呼叫的日誌條目。

但是,我需要查看帶有發送到服務的數據的原始 soap 請求,並且我看不到從 SvcTraceViewer 執行此操作的方法(僅顯示日誌條目,但沒有發送到服務的數據)-我只是缺少配置嗎?

這是我在 web.config 中得到的:

 <system.diagnostics>
   <sources>
     <source name="System.ServiceModel"
             switchValue="Verbose"
             propagateActivity="true">
       <listeners>
         <add name="sdt"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData="App_Data/Logs/WCFTrace.svclog"  />
       </listeners>
     </source>
   </sources>
 </system.diagnostics>

任何幫助表示讚賞!

更新:這就是我在跟踪中看到的全部內容:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
 <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
   <EventID>262163</EventID>
   <Type>3</Type>
   <SubType Name="Information">0</SubType>
   <Level>8</Level>
   <TimeCreated SystemTime="2010-05-10T13:10:46.6713553Z" />
   <Source Name="System.ServiceModel" />
   <Correlation ActivityID="{00000000-0000-0000-1501-0080000000f6}" />
   <Execution ProcessName="w3wp" ProcessID="3492" ThreadID="23" />
   <Channel />
   <Computer>MY_COMPUTER_NAME</Computer>
 </System>
<ApplicationData>
 <TraceData>
   <DataItem>
     <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
       <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Channels.MessageSent.aspx</TraceIdentifier>
         <Description>Sent a message over a channel.</Description>
           <AppDomain>MY_DOMAIN</AppDomain>
           <Source>System.ServiceModel.Channels.HttpOutput+WebRequestHttpOutput/50416815</Source>
           <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord">
           <MessageProperties>
             <Encoder>text/xml; charset=utf-8</Encoder>
             <AllowOutputBatching>False</AllowOutputBatching>
             <Via>http://xxx.xx.xxx.xxx:9080/MyWebService/myService</Via>
           </MessageProperties>
         <MessageHeaders></MessageHeaders>
       </ExtendedData>
     </TraceRecord>
   </DataItem>
 </TraceData>
</ApplicationData>

您沒有僅顯示 SOAP 消息的特定選項卡 - 但 XML 選項卡確實包含整個 SOAP 消息 - 不是嗎?

替代文字

這裡的這段 XML 片段對您來說缺少什麼?

**更新:**約翰,很遺憾,您沒有顯示您的<system.serviceModel>/<diagnostics>部分的外觀 - 我用於此結果的部分如下所示:

<diagnostics>
 <messageLogging 
     logMessagesAtTransportLevel="true" 
     logMessagesAtServiceLevel="false"
     logMalformedMessages="true" 
     logEntireMessage="true"
     maxSizeOfMessageToLog="65535000" 
     maxMessagesToLog="500" />
</diagnostics>

你有同樣的設置嗎?也許你失踪了logEntireMessage或其他什麼?

引用自:https://stackoverflow.com/questions/2802590