title: Using web.config in a Self-Hosted c# WCF console app (setting MaxStringContentLength server side)
body: <p>I have a simple <strong>self hosted</strong> WCF Console windows app, and I can connect fine from my client.
  I have a problem though sending large XML strings through to the server. I get the following error:</p>
  
  <p>"System.Xml.XmlException: The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the <strong>MaxStringContentLength</strong> property on the XmlDictionaryReaderQuotas..."</p>
  
  <p>I can set the <strong>MaxStringContentLength</strong> in the <strong>client</strong> by changing its app.config file (generated by svcutil.exe).</p>
  
  <p>But on the server side I have nowhere I can change this. I have read about a <strong>web.config</strong> file and am not sure if a WCF console app can have one and if so how I can read it in and use it? My self hosting code is below:</p>
  
  <pre><code>static void RunWCFService()
  {
      // Step 1 of the address configuration procedure: Create a URI to serve as the base address.
      Uri baseAddress = new Uri("http://localhost:8000/MyService/WcfService");
  
      // Step 2 of the hosting procedure: Create ServiceHost
      ServiceHost selfHost = new ServiceHost(typeof(MyServiceWcf), baseAddress);
      try
      {
          // Step 3 of the hosting procedure: Add a service endpoint.
          selfHost.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "MyService");
  
          // Step 4 of the hosting procedure: Enable metadata exchange.
          ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
          smb.HttpGetEnabled = true;
          selfHost.Description.Behaviors.Add(smb);                
  
          // Step 5 of the hosting procedure: Start (and then stop) the service.
          selfHost.Open();
          Console.WriteLine("Press &lt;ENTER&gt; to terminate service.");       
          Console.ReadLine();
          // Close the ServiceHostBase to shutdown the service.
          selfHost.Close();
      }
      catch (CommunicationException ce)
      {
          Console.WriteLine("An exception occurred: {0}", ce.Message);
          selfHost.Abort();
      }
   }
  </code></pre>