Search code examples
wcfwcf-configuration

Configuring the beast


Can anybody guide me on WCF configuration, I was getting errors (400) Bad Request and trace viewer told me that:

"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."

I've looked to my client's app.config and changed properties accordingly, but the problem remained, then I've looked to server's web.config where I've found there is no <service>...</service> tag at all, so I've right-clicked web.config and selected Edit WCF configuration a window pop-upped several clicks and my wcf service configuration is ready BUT it started throwing

"The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error"

Trace viewer shows 3 warnings:

"Failed to open System.ServiceModel.ServiceHost"

"Faulted System.ServiceModel.ServiceHost"

"ServiceHost faulted"

Here are my server web.configs:

Version 0 (working but with limitations):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces1.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata 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" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

And the one that shows 3 warnings:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces1.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="NewServiceType">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1948/Commander.svc" />
          </baseAddresses>
        </host>
      </service>
      <service name="Populator.Commander">
        <endpoint address="http://localhost:1948/Commander.svc" binding="basicHttpBinding"
          bindingConfiguration="" name="CommanderEndpoint" contract="Private.ICommander" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata 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" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

EDIT

This is Version #3 of my web config still shows the same three warnings in TraceViewer

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <connectionStrings>
    <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="httpBasicBinding_Service01" closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
          maxBufferSize="655360000"
          maxBufferPoolSize="655360000" maxReceivedMessageSize="655360000">
          <readerQuotas maxDepth="655360000" maxStringContentLength="655360000"
            maxArrayLength="655360000" maxBytesPerRead="655360000" maxNameTableCharCount="655360000" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="NewServiceType">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1948/Commander.svc" />
          </baseAddresses>
        </host>
      </service>
      <service name="Populator.Commander">
        <endpoint address="http://localhost:1948/Commander.svc" binding="basicHttpBinding"
          bindingConfiguration="httpBasicBinding_Service01" name="CommanderEndpoint" contract="Private.ICommander" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata 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" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

Solution

  • Step by step configuration from working to non-working version of configuration helped out. Here's the server's web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
              <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces.svclog" />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>
      <connectionStrings>
        <add name="PopulizerConnectionString" connectionString="Data Source=VM-LU4\SQLSERVER;Initial Catalog=Populizer;Integrated Security=True" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
      </system.web>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding  name="ICommander_BindingConfiguration"
                      closeTimeout="01:00:00"
                      openTimeout="00:01:00"
                      receiveTimeout="00:10:00"
                      sendTimeout="00:01:00"
                      allowCookies="false"
                      bypassProxyOnLocal="false"
                      hostNameComparisonMode="StrongWildcard"
                      maxBufferSize="1048576"
                      maxBufferPoolSize="524288"
                      maxReceivedMessageSize="1048576"
                      messageEncoding="Text"
                      textEncoding="utf-8"
                      transferMode="Buffered"
                      useDefaultWebProxy="true"
            >
              <readerQuotas
                  maxDepth="32"
                  maxStringContentLength="1048576"
                  maxArrayLength="1048576"
                  maxBytesPerRead="4096"
                  maxNameTableCharCount="1048576"
              />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
            <binding
              name="ICommunicator_BindingConfiguration"
              closeTimeout="01:00:00"
              openTimeout="00:01:00"
              receiveTimeout="00:10:00"
              sendTimeout="00:01:00"
              allowCookies="false"
              bypassProxyOnLocal="false"
              hostNameComparisonMode="StrongWildcard"
              maxBufferSize="1048576"
              maxBufferPoolSize="524288"
              maxReceivedMessageSize="1048576"
              messageEncoding="Text"
              textEncoding="utf-8"
              transferMode="Buffered"
              useDefaultWebProxy="true"
            >
              <readerQuotas
                  maxDepth="32"
                  maxStringContentLength="1048576"
                  maxArrayLength="1048576"
                  maxBytesPerRead="4096"
                  maxNameTableCharCount="1048576"
              />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <services>
          <service name="Populator.Commander">
            <endpoint contract="Private.ICommander" binding="basicHttpBinding" bindingConfiguration="ICommander_BindingConfiguration" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="CommanderBehavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata 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" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>
    </configuration>