Detailed Errors not working for WCF Service in IIS

11,943

WCF tracing can be more complex to configure that the usual web.config settings for an IIS web site.

If you want the information returned to the client (which should only be done in development), try the includeExceptionDetailInFaults setting:

  <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

However, a far more useful tool is the tracing to a file that you can process with the Service Trace Viewer application. This is typically located at: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\svctraceviewer.exe on your machine where you have your Windows Development SDK installed.

Configuring Tracing
http://msdn.microsoft.com/en-us/library/ms733025.aspx

Service Trace Viewer Tool (SvcTraceViewer.exe)
http://msdn.microsoft.com/en-us/library/ms732023.aspx

You can log transport-level activity, and if you have message security, message activity. Usually a separate file is created for each. An example of one way to configure:

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

Assuming everything is configured correctly, the files will be generated. When the exception occurs, you can copy the file to the machine where svctraceviewer is installed, and open it. Typically you can navigate to the datetime when the issue occurred and find it. If you are sifting through a lot of activity, svctraceviewer has excellent filtering. Exceptions appear highlighted as red in the left pane. You can click on the exception to find the exception detail.

enter image description here

Share:
11,943

Related videos on Youtube

Marcus
Author by

Marcus

Updated on September 18, 2022

Comments

  • Marcus
    Marcus over 1 year

    If I were to change the web.config file to have errors in it, I only see the standard 500 - Internal Server Page.

    Despite setting the Error Pages mode to Detailed, I can't see a detailed error message. How do I sort this?

    The reason is I'm wanting to make changes to a WCF service to add tracing, but that gives a 500 error, so I want to see what this 500 error is.

    I have the following in the web.config file:

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