2

After two days of try and error and blind debugging, my web service still produces some error in certain cases and for now, I don't know why. Therefor, I would like to enable tracing for the service in order to have at least a little feedback.

However, I tried a few addition to the web.config, but none ever produced a trace file, even if the service responded with an error.

So long, this is my web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <configSections>
    <section name="entityFramework"        type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
     </configSections>
     <connectionStrings>
     <...removed here... />
     </connectionStrings>
    <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
    <customErrors mode="Off"></customErrors>
    <compilation targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    </system.web>
    <system.serviceModel>
    <services>
      <service name="TimeRecHomePage.Service.TimeService" behaviorConfiguration="TimeServiceBehavior">
        <endpoint name="webHttpBinding" address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" contract="TimeRecHomePage.Service.ITimeService" behaviorConfiguration="webHttp" />
        <endpoint name="mexHttpBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
      </services>
      <bindings>
      <webHttpBinding>
        <binding name="webHttpTransportSecurity">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="TimeServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" defaultBodyStyle="WrappedRequest" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" />
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      </assemblyBinding>
     </runtime>
     </configuration>

I already looked up the configuration of the tracing and tested the entries for the web.config proposed e.g.here, here and also read the documentation.

As it is written in the documentation, that from Windows 8 on, you need privileged rights in order to trace, I also changed the application pool identity, without success though (the service runs on an Win 2012 R2 server).

What am I missing in order to enable and use tracing? Thank you in advance for your efforts!

Community
  • 1
  • 1
bogrub
  • 23
  • 4

1 Answers1

3

You need two sections in your web.config, one is where the tracelisteners are configured and the diagnostics section in system.serviceModel.

system.diagnostics

Add the following section:

<system.diagnostics>
  <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\temp\messages.svclog" />
          </listeners>
      </source>
      <source name="System.ServiceModel" switchValue="Information,ActivityTracing"
    propagateActivity="true">
        <listeners>
              <add name="tracing"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\temp\tracing.svclog" />
        </listeners>
      </source>
    </sources>
</system.diagnostics>

Notice the value of initializeData and make sure you add a path there where the application identity can write. A system wide tempfolder should be an option.

system.serviceModel diagniostics

Adapt your system.serviceModel nd add the diagnostics settings

<system.serviceModel>
  <diagnostics>
    <messageLogging 
         logEntireMessage="true" 
         logMalformedMessages="true"
         logMessagesAtServiceLevel="true" 
         logMessagesAtTransportLevel="true"
         maxMessagesToLog="3000"
         maxSizeOfMessageToLog="2000"/>
  </diagnostics>
  <!-- your other stuff here -->
</system.serviceModel>

Test your settings

With the above config your logifiles should be created and the tracing.scvlog should show entries when the service is started or when you request the wsdl for your service. It also holds any exceptions and stacktraces that occur.

rene
  • 41,474
  • 78
  • 114
  • 152