title: How do I cause SecurityTokenServiceConfiguration to load configuration information from the app.config?
body: <p>I am creating an STS with the WIF framework included in .NET 4.5. I am self-hosting this STS (for now), using the <code>WSTrustServiceHost</code> class. In order to do that, I am doing the following:</p>
  
  <pre><code>var conf = new SecurityTokenServiceConfiguration("isser name here", true)
  {
      DisableWsdl          = true,
      SecurityTokenService = typeof(MyTokenService),
  };
  var ct   = new WSTrustServiceContract(conf);
  var host = new WSTrustServiceHost(ct);
  
  host.Open();
  // ...
  </code></pre>
  
  <p>As you can see, I'm passing in <code>true</code> to the <code>loadConfig</code> parameter of the <code>SecurityTokenServiceConfiguration</code> constructor, which, says the documentation:</p>
  
  <blockquote>
    <p><strong>true</strong> to load settings from the configuration file; otherwise <strong>false</strong>.</p>
  </blockquote>
  
  <p>I have an <code>identityConfiguration</code> element in my configuration file, but it does not seem to be loaded. I can make changes to the configuration file, f.e. I can alter the <code>securityTokenHandlers</code>, and those changes are not reflected in the constructed <code>SecurityTokenServiceConfiguration</code>.</p>
  
  <p>In my app.config file, I have the following:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior name="sts_behavior"&gt;
                  &lt;serviceCredentials useIdentityConfiguration="true" identityConfiguration="the_issuer_id"&gt;
                      &lt;serviceCertificate findValue="7A5D7EB05EC741E45BF4EDA7E574F58DC31EF290" x509FindType="FindByThumbprint" storeName="My" storeLocation="LocalMachine" /&gt;
                  &lt;/serviceCredentials&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
          &lt;ws2007HttpBinding&gt;
              &lt;binding name="sts_binding"&gt;
                  &lt;security mode="Message"&gt;
                      &lt;message clientCredentialType="UserName" /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/ws2007HttpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
          &lt;service name="System.ServiceModel.Security.WSTrustServiceContract" behaviorConfiguration="sts_behavior"&gt;
              &lt;endpoint address="http://my-machine:54512/tokens" binding="ws2007HttpBinding" contract="System.ServiceModel.Security.IWSTrust13SyncContract" bindingConfiguration="sts_binding" /&gt;
          &lt;/service&gt;
      &lt;/services&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>As one can see, the <code>&lt;serviceCredentials&gt;</code> element refers to the <code>&lt;identityConfiguration&gt;</code> element present in the config file, and if I change this name to not match that <code>&lt;identityConfiguration&gt;</code> element, an error is thrown when the service host is opened. This <code>&lt;identityConfiguration&gt;</code> element is still not used, however, as I can <code>&lt;clear/&gt;</code> the security token handlers, and a token handler is still used when a request comes in.</p>
  
  <p>How can I configure and self-host a custom STS with a minimum of programmatic configuration?</p>