title: Dynamically create WCF ServiceHost based on parsing Endpoint Address with NamedNetPipes Binding
body: <p>Need a way for one service on a well-known Endpoint to return strings which are relative addresses. The client can then connect to Endpoints using these relative addresses.
  Clearly this resembles REST in some ways, but in this case running a Windows Service using NetNamedPipeBinding for IPC, so no need for HTTP.</p>
  
  <p>Don't want to create the Endpoint ahead of time since there will be a potentially large number of relative addresses, only some of which the client would be interested in.</p>
  
  <p>All Contracts are known in advance.</p>
  
  <p>Tried to find a solution with <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.addressfiltermode.aspx" rel="nofollow">AddressFilterMode</a> but wasn't sure how to provision new Binding so that client connected to it, <a href="http://msdn.microsoft.com/en-us/library/system.uritemplate.aspx" rel="nofollow">UriTemplate</a> but don't want to use the HTTP framework. Haven't looked into <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.routing.routingservice.aspx" rel="nofollow">RoutingService</a> because constrained to .Net 3.5.</p>
  
  <p>Pseudocode for client would be something like that below...</p>
  
  <pre><code>namespace Testing
  {
      class RunTest
      {
          static void Test()
          {
              NetNamedPipeBinding namedpipe = new NetNamedPipeBinding();
              ChannelFactory&lt;Contracts.IRoot&gt; factoryRoot =
                  new ChannelFactory&lt;Contracts.IRoot&gt;(
                  namedpipe
                  , new EndpointAddress("net.pipe://localhost/root");
              );
              Contracts.IRoot root = factoryRoot.CreateChannel();
              ICommunicationObject commsRoot = root as ICommunicationObject;
              commsRoot.Open();
  
              // Service examines address and creates Endpoint dynamically.
              string address = root.SomeFunctionWhichGetsARelativeAddress();
  
              // IBar service routes endpoint requests internally based on
              // "address" variable.
              ChannelFactory&lt;Contracts.IBar&gt; factoryBar = 
                  new ChannelFactory&lt;Contracts.IBar&gt;(
                  namedpipe
                  , new EndpointAddress("net.pipe://localhost/root/IBar/" +
                                         address)
              );
              Contracts.IBar bar = factoryBar.CreateChannel();
              bar.DoSomething();
          }
      } // Ends class RunTest
  } // Ends namespace Testing
  </code></pre>