WCF服务跟踪
如果在开发过程中,WCF服务出现问题,我们可以通过服务引用,然后直接断点调试进去。然而,对于已经发布的服务,出现错误时,寻找错误信息会变得麻烦。
幸好,微软提供了服务跟踪查看器工具 (SvcTraceViewer.exe)这个工具来跟踪已发布的服务。
可以在文件夹: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin找到(我的系统是WIN7,.NET 4.0)
配置服务跟踪相当简单,可以用上面的SvcConfigEditor.exe来打开服务的config文件配置。
也可以手动修改配置,增加一个diagnostics的配置节点。
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <compilation targetFramework="4.5" /> <httpRuntime targetFramework="4.5"/> </system.web> <system.serviceModel>
<!--添加跟踪节点-->
<diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" /> </diagnostics> <behaviors> <serviceBehaviors> <behavior> <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false --> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <bindings> <basicHttpBinding> <binding name="ServiceProxyBinding" closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxStringContentLength="2147483647" /> </binding> <binding name="BasicHttpBinding_IAircraftService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> <binding name="BasicHttpBinding_ITransCenter" /> <binding name="BasicHttpBinding_IDecodeService" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://192.168.85.70:5596/TransCenterSer.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransCenter" contract="TransCenterSer.ITransCenter" name="BasicHttpBinding_ITransCenter" /> <endpoint address="http://192.168.85.70:8010/AHMTService/DecodeService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDecodeService" contract="DecodeService.IDecodeService" name="BasicHttpBinding_IDecodeService" /> </client> </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> <source name="System.ServiceModel" switchValue="Warning, ActivityTracing" propagateActivity="true"> <listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default"> <filter type="" /> </add> <add name="ServiceModelTraceListener"> <filter type="" /> </add> </listeners> </source> </sources> <sharedListeners> <add initializeData="D:\LogData\MoveQarData_messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> <filter type="" /> </add> <add initializeData="D:\LogData\MoveQarData_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp"> <filter type="" /> </add> </sharedListeners> <trace autoflush="true" /> </system.diagnostics> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <!-- 若要在调试过程中浏览 Web 应用程序根目录,请将下面的值设置为 True。 在部署之前将该值设置为 False 可避免泄露 Web 应用程序文件夹信息。 --> <directoryBrowse enabled="true"/> </system.webServer> </configuration>
参考:http://msdn.microsoft.com/zh-cn/library/ms732023.aspx
http://www.cnblogs.com/cbcye/archive/2009/06/02/1494734.html
http://www.cnblogs.com/cnblogsfans/archive/2009/03/16/1413069.html
如果我的文章对你有帮助,就点一下推荐吧.(*^__^*)