title: Declaratively configure WCF behavior extension on programmatically constructed endpoint
body: <p>I have a WCF behavior extension that I would like to add to a WCF client. However, the client is constructed programmatically. The endpoint address may vary, but I know the type. I could add the behavior programmatically or in the config file (preferred), but I need to pass some configuration in the config file only.</p>
  
  <p>I don't want this in Common behaviors (machine.config).  </p>
  
  <p>I can add the behavior programmatically</p>
  
  <pre><code>endpoint.Behaviors.Add(new MyCustomBehavior())
  </code></pre>
  
  <p>But I'd rather do it in config, so I can configure the extension there as well.</p>
  
  <p>Is it possible to declaratively add and configure an endpoint behavior extension to a programmatically constructed endpoint knowing only the the type or interface while leaving the client endpoint to be constructed programmatically?</p>
  
  <pre><code>&lt;system.serviceModel&gt;
    &lt;client&gt;
      &lt;!-- Created programmatically --&gt;
    &lt;/client&gt;
  &lt;extensions&gt;
    &lt;behaviorExtensions&gt;
      &lt;add name="MyCustomBehavior" type="namespace.CustomBehaviors", MyAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
    &lt;/behaviorExtensions&gt;   
  &lt;/extensions&gt;
    &lt;behaviors&gt;
      &lt;endpointBehaviors&gt;
        &lt;behavior name="MyCustomBehavior"&gt;
          &lt;MyCustomBehavior MyImportantBehaviorParam1="foo"  /&gt;
        &lt;/behavior&gt;
      &lt;/endpointBehaviors&gt;   
    &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Of course I could put the config in another section, and have my behavior read it there, but I'd rather use the WCF facilities if possible.</p>