Simplified Configuation Files explained on Snippet from MSDN: Configuring Windows Communication Foundation (WCF) services can be a complex task. There are many different options and it is not always easy to determine what settings are required. While configuration files increase the flexibility of WCF services, they also are the source for many hard to find problems. .NET Framework 4.5 addresses these problems and provides a way to reduce the size and complexity of service configuration.
Create folder named configs and place your various configs into it. The idea here is to separate out the section into their our config files.
Your configuration file could look something like this (the App.config or Web.config could have these with the matching files instead of having the actual section within the same config file):
<configuration> <system.serviceModel> <services configSource=”Services.config” > </services> <bindings configSource=”Bindings.config”></bindings> <behaviors configSource=”Behaviors.config”> </behaviors> </system.serviceModel> </configuration>
Note: Each of the above basically point to the files loacted at the same level as the App.config or Web.Config file (you can place them into a folder names configs and update the configSource location etc.)
Examples: behaviours.config
<?xml version=”1.0″ encoding=”utf-8″ ?> <behaviors> <serviceBehaviors> <behavior name=”defaultBehavior”> <serviceMetadata httpGetEnabled=”false” /> <serviceAuthorization impersonateCallerForAllOperations=”true” /> <serviceCredentials> <windowsAuthentication includeWindowsGroups=”true” allowAnonymousLogons=”false”/> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors>
or
<?xml version=”1.0″ encoding=”utf-8″ ?> <behaviors> <serviceBehaviors> <behavior> <!– To avoid disclosing metadata information, set the values below to false before deployment –> <serviceMetadata httpGetEnabled=”true” httpsGetEnabled=”false” /> <!–Suppports Impersonation–> <serviceAuthorization impersonateCallerForAllOperations=”false” /> <!– 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” /> <!–2014 01 02–> <dataContractSerializer maxItemsInObjectGraph=”2147483647″/> </behavior> </serviceBehaviors> </behaviors>
bindings.config
<?xml version=”1.0″ encoding=”utf-8″ ?> <bindings> <basicHttpBinding> <binding name=”HttpBinding_IDataService” closeTimeout=”01:00:00″ openTimeout=”01:00:00″ receiveTimeout=”01:00:00″ sendTimeout=”01:00:00″ bypassProxyOnLocal=”false” hostNameComparisonMode=”StrongWildcard” maxBufferPoolSize=”2147483647″ maxReceivedMessageSize=”2147483647″ messageEncoding=”Text” textEncoding=”utf-8″ useDefaultWebProxy=”true” allowCookies=”false”> <readerQuotas maxDepth=”16384″ maxStringContentLength=”2147483647″ maxArrayLength=”2147483647″ maxBytesPerRead=”2147483647″ maxNameTableCharCount=”2147483647″ /> <security mode=”TransportCredentialOnly”> <transport clientCredentialType=”Windows” proxyCredentialType=”Windows” /> </security> </binding> </basicHttpBinding> </bindings>
or
textEncoding=”utf-8″ transferMode=”Buffered” useDefaultWebProxy=”true”> <readerQuotas maxDepth=”32″ maxStringContentLength=”2147483647″ maxArrayLength=”16384″ maxBytesPerRead=”4096″ maxNameTableCharCount=”16384″ /> <security mode=”Transport”> <transport clientCredentialType=”None” proxyCredentialType=”None” realm=””/> <message clientCredentialType=”UserName” algorithmSuite=”Default”/> </security> </binding> </basicHttpBinding> </bindings>
client.config
<?xml version=”1.0″ encoding=”utf-8″ ?> <client> <endpoint address=”” binding=”basicHttpBinding” bindingConfiguration=”BindingConfigurationToUse” contract=”” name=”YourClientConfigName”/>
<endpoint address= binding=”basicHttpBinding” bindingConfiguration=”BindingConfigurationToUse” contract=”YourContractAddress” name=”YourClientConfigName”/> </client>
services.config
<?xml version=”1.0″ encoding=”utf-8″ ?> <services> <service name=”YourServiceNameToUse” behaviorConfiguration=”defaultBehavior”> <endpoint address=”net.tcp://localhost:8998/YourAddress/” binding=”netTcpBinding” bindingConfiguration=”netTcpBindingConfiguration” contract=”YourContractInterfaceToUse”> <identity> <userPrincipalName value=”YourUserPrincipalName” /> </identity> </endpoint> </service> </services>
Related: system.serviceModel, configSource attribute , <services configSource=”Services.config” >, App.config, Web.config