2010-01-25 6 views
3

datacontract 클래스로 deserialize되기 전에 xml이 내 WCF REST 서비스로 전송되는 것을 기록하려면 어떻게해야합니까?WCF REST 디버깅

답변

4

WCF 추적을 사용하여 원시 XML 메시지를 기록 할 수 있습니다.

추적은 기본적으로 사용되지 않습니다. 응용 프로그램의 구성 파일을 편집하여 추적을 사용 가능하게하고 구성 할 수 있습니다. 다음 .config 예는 WCF 원시 메시지 로깅과 추적을 할 수 있습니다 :

<configuration> 
    <system.serviceModel> 
    <diagnostics> 
     <messageLogging maxMessagesToLog="30000" 
       logEntireMessage="true" 
       logMessagesAtServiceLevel="true" 
       logMalformedMessages="true" 
       logMessagesAtTransportLevel="true"> 
     </messageLogging> 
    </diagnostics> 
    </system.serviceModel> 
    <system.diagnostics> 
    <sources> 
     <source name="System.IdentityModel" 
       switchValue="Verbose" 
       logKnownPii="true"> 
     <listeners> 
      <add name="xml" /> 
     </listeners> 
     </source> 
     <!-- Log all messages in the 'Messages' tab of SvcTraceViewer. --> 
     <source name="System.ServiceModel.MessageLogging"> 
     <listeners> 
      <add name="xml" /> 
     </listeners> 
     </source> 
     <!-- ActivityTracing and propogateActivity are used to 
      flesh out the 'Activities' tab in SvcTraceViewer to 
      aid debugging. --> 
     <source name="System.ServiceModel" 
       switchValue="Error, ActivityTracing" 
       propagateActivity="true"> 
     <listeners> 
      <add name="xml" /> 
     </listeners> 
     </source> 
     <!-- This records Microsoft.IdentityModel generated traces, 
      including exceptions thrown from the framework. --> 
     <source name="Microsoft.IdentityModel" switchValue="Warning"> 
     <listeners> 
      <add name="xml" /> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add name="xml" 
      type="System.Diagnostics.XmlWriterTraceListener" 
      initializeData="C:\logs\trace.svclog" /> 
    </sharedListeners> 
    <trace autoflush="true" /> 
    </system.diagnostics> 
</configuration> 

당신은 MSDN: Configuring Tracing에서 추적 WCF에 대한 자세한 내용을보실 수 있습니다.

Microsoft는 Service Trace Viewer Tool을 사용하여 .svclog 파일을 읽습니다.

initializeData에 정의 된 경로가 서비스에서 쓸 수 있는지 확인하십시오.

+1

서비스 추적 뷰어가 멋지다. – Jay

1

원시 HTTP 트래픽을 살펴 보려면 Fiddler과 같은 프록시 도구가 가장 간단합니다. POST/PUT 된 모든 정보를 REST 서비스에서 볼 수 있습니다.

"항상 파일의 특정 위치에 HTTP 트래픽 작성"에서처럼 "로그"를 의미하는 경우 내장 추적을 사용하여 대부분의 작업을 수행 할 수 있습니다. 이 작업을 수행하는 예는 Here is a link이고, 그렇지 않으면 온라인에서 "WCF 추적"을 찾으십시오. 훌륭한 사례가 많이 있습니다.