title: Adding WCF Message Inspectors at Runtime
body: <p>I have created a custom ServiceHost that I would like to use to automatically add a message inspector to every endpoint of a service that is running on it.  I have created a MessageInspector that implements IDispatchMessageInspector and IClientMessageInspector and have found the following code that is supposed to add it to every endpoint:</p>
  
  <pre><code>foreach (ChannelDispatcher channel in this.ChannelDispatchers) {
    foreach (EndpointDispatcher endpoint in channel.Endpoints) {
        endpoint.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector());
     }
  }
  </code></pre>
  
  <p>The problem I run into is that the ChannelDispatchers collection is empty until the servicehost is opened, which means I can't run this code in the constructor.  I created an event handler for the Opened event and used that code in there instead, but then I get the following error when trying to add an endpoint:</p>
  
  <pre><code>This value cannot be changed after a ServiceHost has been opened
  </code></pre>
  
  <p>It seems that I am caught in some sort of a Catch 22, is the functionality I am seeking possible within WCF?</p>
  
  <p>Thanks,</p>
  
  <p>Mike</p>