Jump to: navigation, search

Difference between revisions of "Configuration Files/web.config"


(Example 3.5)
(Example 3.5)
Line 40: Line 40:
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<configuration>   
 
<configuration>   
<configSections>  
+
<configSections>  
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,  
+
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,                 Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"                 requirePermission="true" />
                  Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  
+
<section name="exceptionHandling"                 type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings,                    Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,                    PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
                  requirePermission="true" />
+
</configSections>     
<section name="exceptionHandling"  
+
<loggingConfiguration configSource="Logging.config" />
                  type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings,  
+
<exceptionHandling>
                     Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,  
+
<exceptionPolicies>
                     PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
+
<add name="System.Exception">     
</configSections>     
+
<exceptionTypes>
<loggingConfiguration configSource="Logging.config" />
+
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral,                                            PublicKeyToken=b77a5c561934e089"
<exceptionHandling>
+
postHandlingAction="None">  
<exceptionPolicies>
+
<exceptionHandlers>
<add name="System.Exception">     
+
<add name="System.Exception"  
<exceptionTypes>
+
type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,  
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral,  
+
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral,  
                                           PublicKeyToken=b77a5c561934e089"
+
PublicKeyToken=31bf3856ad364e35"
postHandlingAction="None">  
+
logCategory="EXCEPTION" eventId="100" severity="Error" title="System.Exception"
<exceptionHandlers>
+
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,  
<add name="System.Exception"  
+
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,  
                                                          type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,  
+
PublicKeyToken=31bf3856ad364e35"
                                                          Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral,  
+
priority="0" />
                                                          PublicKeyToken=31bf3856ad364e35"
+
</exceptionHandlers>
  logCategory="EXCEPTION" eventId="100" severity="Error" title="System.Exception"
+
</add>
                                                          formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,  
+
</exceptionTypes>
                                                          Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,  
+
</add>
                                                          PublicKeyToken=31bf3856ad364e35"
+
</exceptionPolicies>
priority="0" />
+
</exceptionHandling>
</exceptionHandlers>
+
<appSettings  configSource="AppSettings.config" />
</add>
+
<runtime>
</exceptionTypes>
+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</add>
+
<probing privatePath="bin\lib;injection"/>
</exceptionPolicies>
+
</assemblyBinding>
</exceptionHandling>
+
<appSettings  configSource="AppSettings.config" />
+
<runtime>
+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+
<probing privatePath="bin\lib;injection"/>
+
</assemblyBinding>
+
 
</runtime>
 
</runtime>
<system.web>
+
<system.web>
<customErrors mode="Off"/>
+
<customErrors mode="Off"/>
<httpRuntime maxRequestLength="65536" />
+
<httpRuntime maxRequestLength="65536" />
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0" />
+
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0" />
</system.web>
+
</system.web>
<system.serviceModel>
+
<system.serviceModel>
<behaviors>
+
<behaviors>
<serviceBehaviors>
+
<serviceBehaviors>
<behavior name="httpBehavior">
+
<behavior name="httpBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint  
+
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint                                         above before deployment -->
                                          above before deployment -->
+
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
+
<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before  
<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before  
+
deployment to avoid disclosing exception information -->
                                            deployment to avoid disclosing exception information -->
+
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
+
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
+
</behavior>
</behavior>
+
</serviceBehaviors>
</serviceBehaviors>
+
<endpointBehaviors>
<endpointBehaviors>
+
<behavior name="httpBehavior">
<behavior name="httpBehavior">
+
<webHttp />
<webHttp />
+
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
+
</behavior>
</behavior>
+
</endpointBehaviors>
</endpointBehaviors>
+
</behaviors>
</behaviors>
+
<bindings configSource="Bindings.config" />
<bindings configSource="Bindings.config" />
+
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
+
<services configSource="Services.config" />
<services configSource="Services.config" />
+
<client configSource="Client.config" />
<client configSource="Client.config" />
+
</system.serviceModel>
</system.serviceModel>
+
<system.webServer>
<system.webServer>
+
<modules runAllManagedModulesForAllRequests="true" />
<modules runAllManagedModulesForAllRequests="true" />
+
<directoryBrowse enabled="true" />
<directoryBrowse enabled="true" />
+
<validation validateIntegratedModeConfiguration="false" />
<validation validateIntegratedModeConfiguration="false" />
+
<security>             
<security>             
+
<requestFiltering>
<requestFiltering>
+
<requestLimits maxAllowedContentLength="524288000"/>
<requestLimits maxAllowedContentLength="524288000"/>
+
</requestFiltering>
</requestFiltering>
+
</security>
</security>
+
</system.webServer>
</system.webServer>
+
<runtime>
<runtime>
+
<assemblyBinding>
<assemblyBinding>
+
<probing privatePath="bin\lib;injection"/>
<probing privatePath="bin\lib;injection"/>
+
<dependentAssembly>
<dependentAssembly>
+
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
+
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" />
+
</dependentAssembly>
</dependentAssembly>
+
</assemblyBinding>
</assemblyBinding>
+
</runtime>
</runtime>
+
<system.diagnostics>
<system.diagnostics>
+
<sources>
    <sources>
+
<source name="System.ServiceModel.MessageLogging" switchValue="Off, ActivityTracing">
      <source name="System.ServiceModel.MessageLogging" switchValue="Off, ActivityTracing">
+
<listeners>
        <listeners>
+
<add name="ServiceModelTraceListener" />
          <add name="ServiceModelTraceListener" />
+
</listeners>
        </listeners>
+
</source>
      </source>
+
<source name="System.ServiceModel" switchValue="Off,ActivityTracing">
      <source name="System.ServiceModel" switchValue="Off,ActivityTracing">
+
<listeners>
        <listeners>
+
<add name="ServiceModelTraceListener" />
          <add name="ServiceModelTraceListener" />
+
</listeners>
        </listeners>
+
</source>
      </source>
+
<source name="System.Runtime.Serialization" switchValue="Off,ActivityTracing">
      <source name="System.Runtime.Serialization" switchValue="Off,ActivityTracing">
+
<listeners>
        <listeners>
+
<add name="ServiceModelTraceListener" />
          <add name="ServiceModelTraceListener" />
+
</listeners>
        </listeners>
+
</source>
      </source>
+
</sources>
    </sources>
+
<sharedListeners>
    <sharedListeners>
+
<add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral,  
      <add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral,  
+
PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
        PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
+
</sharedListeners>
    </sharedListeners>
+
<trace autoflush="true" />
<trace autoflush="true" />
+
</system.diagnostics>
  </system.diagnostics>
+
 
</configuration>
 
</configuration>
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 14:08, 23 March 2021

This is the main configuration file of the web service. The web service is configured using this main configuration file and the specific files.

Sections

These sections will be found only in the web service configuration file.

appSettings

See Configuration Files/AppSettings.config.

system.web

This does not have to be edited in general.

system.webServer

This does not have to edited in general, except the setting for the maximum allowed size of received content. This can be changed by editing the value maxAllowedContentLength within the section requestFiltering/requestLimits.


3.5 Web.config

Added Windows Communication Foundation Tracing in system.diagnostics, which is used in WCF instead of a debugger to understand how an app is behaving or why it faults (fault monitoring and analysis), WCF can output data for diagnostic tracing such as checking all the operation calls, code exceptions, warning and other important (significant processing) events and when the tracing feature malfunctions it can write Windows Error Events.

  • System.ServiceModel.MessageLogging : Logs all messages that flow through the system. It can be added to enhance debugging.
  • System.ServiceModel : Logs all stages of WCF processing, whenever configuration is read, a message is processed in transport, security processing, a message is dispatched in user code, and so on.(Message process, Reading of configuration information, Transport-level action, Security requests).
    • propagetActivity : by using this and setting its value to true, we can take trace files generated by any two endpoints and observe how the set of traces moves from one endpoint to another endpoint. (not used by default but can be turned on if such information is needed, we are using it right now in our Web configuration).
    • ActivityTracing : added if we want to use user-defined trace source.
  • System.Runtime.Serialization : Logs when objects are read or written. Information about object serialization or deserialization. Good to use so we can see the content of requests.
  • System.Diagnostics.XmlWriterTraceListener : is the standard .Net Framework trace listener. Process the data WCF provides in specific output format.
  • Trace Levels:
    • Critical: Logs Fail-Fast and Event Log entries, and trace correlation information. The following are some examples of when you might use the Critical level: Your AppDomain went down because of an unhandled exception. Your application fails to start. The message that caused the failure originated from the process MyApp.exe.
    • Error: Logs all exceptions. You can use the Error level in the following situations: Your code crashed because of an Invalid Cast Exception. A "failed to create endpoint" exception is causing your application to fail on startup.
    • Warning: A condition exists that may subsequently result in an error or critical failure. You can use this level in the following situations: The application is receiving more requests than its throttling settings allows. The receiving queue is at 98 percent of its configured capacity.
    • Information: Messages helpful for monitoring and diagnosing system status, measuring performance, or profiling are generated. You can utilize such information for capacity planning and performance management. You can use this level in the following situations: A failure occurred after the message reached the AppDomain and was deserialized. A failure occurred while the HTTP binding was being created.
    • Verbose: Debug-level tracing for both user code and servicing. Set this level when: You are not sure which method in your code was called when the failure occurred. You have an incorrect endpoint configured and the service failed to start because the entry in the reservation store is locked.
    • ActivityTracing: Flow events between processing activities and components.This level allows administrators and developers to correlate applications in the same application domain. Traces for activity boundaries: start/stop. Traces for transfers.

How to configure

Enabling can be done by simlpy setting the desired log level value of (for e.g. switchValue="Verbose" or higher) Disabling can be done by simply setting the log level value of all three tracers from (e.g. switchValue="Verbose, ActivityTracing?" to switchValue="Off, ActivityTracing?"). By deafult all are set to "Off".

Example 3.5

<?xml version="1.0" encoding="UTF-8"?>
<configuration>  
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,                 Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"                 requirePermission="true" />
<section name="exceptionHandling"                  type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings,                     Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,                     PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>    
<loggingConfiguration configSource="Logging.config" />
<exceptionHandling>
<exceptionPolicies>
<add name="System.Exception">    
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral,                                            PublicKeyToken=b77a5c561934e089"
postHandlingAction="None">
<exceptionHandlers>
<add name="System.Exception"
type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"

logCategory="EXCEPTION" eventId="100" severity="Error" title="System.Exception"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"

priority="0" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
<appSettings  configSource="AppSettings.config" />
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin\lib;injection"/>
</assemblyBinding>
</runtime>
<system.web>
<customErrors mode="Off"/>
<httpRuntime maxRequestLength="65536" />
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="httpBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint                                          above before deployment -->
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before
deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings configSource="Bindings.config" />
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />  
<services configSource="Services.config" />
<client configSource="Client.config" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
<validation validateIntegratedModeConfiguration="false" />
<security>            
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>                    
</security>            
</system.webServer>
<runtime>
<assemblyBinding>
<probing privatePath="bin\lib;injection"/>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Off, ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Off,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
<source name="System.Runtime.Serialization" switchValue="Off,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />

</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
</configuration>

See also