title: WCF: How can I programmatically recreate these App.config values?
body: <p>I have a WCF service that works ok if I create the service without specifying any binding or endpoint (it reads it from the generated values in the App.config when I registered the WCF via Visual Studio).</p>
  
  <p>I have a simple method that returns the service reference:</p>
  
  <pre><code>return new SmsServiceReference.SmsEngineServiceClient();
  </code></pre>
  
  <p>This works ok (because the values are read from the config). However, I'd like to have some of these values in a Database (the URI for example) and would like to do something like this:</p>
  
  <pre><code>        Binding binding = new BasicHttpBinding();
          EndpointAddress endpointAddress = new EndpointAddress( "my.uri.com/service.svc" );
  
          return new SmsServiceReference.SmsEngineServiceClient(binding,endpointAddress);
  </code></pre>
  
  <p>This doesn't work. It throws an exception when I try to use the service reference.</p>
  
  <p>I suspect that this is because my App.config has more information that the two lines up there are not providing (obviously). The question is, how can I replicate the following App.Config values programmatically?</p>
  
  <p>Here's the fragment of my App.Config: (the URI has been altered to protect the innocent).</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
  &lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="BasicHttpBinding_ISmsEngineService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true"&gt;
        &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
        &lt;security mode="None"&gt;
          &lt;transport clientCredentialType="None" proxyCredentialType="None"
              realm="" /&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;client&gt;
    &lt;endpoint address="http://www.myuri.com/Services/Services.svc/basic"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISmsEngineService"
        contract="SmsServiceReference.ISmsEngineService" name="BasicHttpBinding_ISmsEngineService" /&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p></p>