详细的错误不适用于IIS中的WCF服务

如果我要更改web.config文件中有错误,我只能看到标准的500 – 内部服务器页面。

尽pipe将“错误页面”模式设置为“详细”,但我看不到详细的错误消息。 我如何分类?

原因是我想对WCF服务进行更改以添加跟踪,但是这给出了一个500错误,所以我想看看这个500错误是什么。

我在web.config文件中有以下内容:

<system.webServer> <httpErrors errorMode="Detailed" /> ... </system.webServer> <system.web> <customErrors mode="Off" /> ... </system.web> 

WCF跟踪可能会更复杂,以便为IIS网站configuration常用的web.config设置。

如果您希望返回给客户端的信息(只能在开发中完成),请尝试includeExceptionDetailInFaults设置:

  <system.serviceModel> <serviceBehaviors> <behavior name="metadataAndDebugEnabled"> <serviceDebug includeExceptionDetailInFaults="true" /> <serviceMetadata httpGetEnabled="true" httpGetUrl="" /> </behavior> </serviceBehaviors> </system.serviceModel> 

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.includeexceptiondetailinfaults.aspx

但是,更有用的工具是跟踪可以使用Service Trace Viewer应用程序处理的文件。 这通常位于安装了Windows开发SDK的计算机上的C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\svctraceviewer.exe

configuration跟踪
http://msdn.microsoft.com/en-us/library/ms733025.aspx

服务跟踪查看器工具(SvcTraceViewer.exe)
http://msdn.microsoft.com/en-us/library/ms732023.aspx

您可以logging传输级别的活动,并且如果您有消息安全性,消息活动。 通常为每个文件创build一个单独的文件。 一种configuration方式的例子:

 <system.diagnostics> <sources> <!-- NOTE: change to switchValue="Warning" for production --> <!--source name="System.ServiceModel" switchValue="Warning" propagateActivity="true"--> <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> <!-- NOTE: change to switchValue="Warning" for production --> <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="C:\logs\app_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp"> <filter type=""/> </add> <add initializeData="C:\logs\app_messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> <filter type=""/> </add> </sharedListeners> </system.diagnostics> 

假设一切正确configuration,文件将被生成。 发生exception时,可以将文件复制到安装了svctraceviewer的机器上,然后将其打开。 通常,您可以导航到问题发生时的date时间并find它。 如果您正在筛选大量活动,svctraceviewer具有出色的过滤function。 在左侧窗格中,exception显示为红色。 您可以单击该例外以查找exception详细信息。

在这里输入图像说明

确保machine.config文件中retail模式选项没有设置为true

它看起来像这样:

 <configuration> <system.web> <deployment retail=”true”/> </system.web> </configuration> 

如果将其设置为true,则将禁用debugging和请求跟踪,并且自定义错误始终为On。 将其设置为false。

要获得运行时环境正在使用的machine.config的path,请在ASP.NET中打印它,如下所示:

 <% string machineConfPath = System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile; Response.Write("System configuration file: {0}", machineConfPath); %>