title: Cannot connect to WCF service hosted in Docker container
body: <p>I'm trying to run an application that exposes a WCF service in a Docker container.</p>
  
  <p>The application is built using TopShelf so it can run either as Windows Service or (in development) as stand-alone console program. </p>
  
  <p>The problem I'm experiencing is that the WCF Test Client can't get the metadata. It's worth saying that the application works correctly when executed locally.</p>
  
  <p>Here is the metadata file generated by the WCF Test Client when the application is running locally</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;netTcpBinding&gt;
                  &lt;binding name="NetTcpBinding_ITestWcfDocker" sendTimeout="00:05:00"&gt;
                      &lt;security mode="None" /&gt;
                  &lt;/binding&gt;
              &lt;/netTcpBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
              &lt;endpoint address="net.tcp://localhost:9998/" binding="netTcpBinding"
                  bindingConfiguration="NetTcpBinding_ITestWcfDocker" contract="ITestWcfDocker"
                  name="NetTcpBinding_ITestWcfDocker" /&gt;
          &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>This is the Dockerfile I'm using the build the container</p>
  
  <pre><code>FROM microsoft/dotnet-framework:4.6.2
  RUN powershell -Command Add-WindowsFeature NET-WCF-HTTP-Activation45
  WORKDIR app
  COPY bin/Release/net461 .
  EXPOSE 9998 9999
  ENTRYPOINT ["EMG.Service.TestWcfDocker.exe"]
  </code></pre>
  
  <p>After building the project, I build the container with this command</p>
  
  <pre><code>docker build -t emg/test-wcf:latest .
  </code></pre>
  
  <p>Then I launch a container with this command</p>
  
  <pre><code>docker run -p 9998:9998 -p 9999:9999 -t emg/test-wcf
  </code></pre>
  
  <p>This is the output I get on the console log</p>
  
  <pre><code>Configuration Result:
  [Success] Name EMG.TestWcfDocker, [Success] DisplayName EMG TestWcfDocker, [Success] Description EMG TestWcfDocker, [Success] ServiceName EMG.TestWcfDocker
  Topshelf v4.0.0.0, .NET Framework v4.0.30319.42000
  2017-05-15 15:46:48.0700|DEBUG|WcfServiceHost|Adding NetTcpBinding endpoint for ITestWcfDocker at net.tcp://localhost:9998/
  2017-05-15 15:46:48.1012|DEBUG|WcfServiceHost|Adding Metadata endpoint at http://localhost:9999/
  2017-05-15 15:46:49.2207|INFO|EMG.TestWcfDocker.Program|Starting EMG.TestWcfDocker
  The EMG.TestWcfDocker service is now running, press Control+C to exit.
  2017-05-15 15:46:50.2675|INFO|EMG.TestWcfDocker.Program|EMG.TestWcfDocker started
  </code></pre>
  
  <p>Once the container is started, I use this to get the IP of the container</p>
  
  <pre><code>docker inspect -f="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" container-name
  </code></pre>
  
  <p>I then use the returned IP to connect to the service via the WCF Test Client, but I receive this error message</p>
  
  <pre><code>Error: Cannot obtain Metadata from http://172.19.111.72:9999/ If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://172.19.111.72:9999/    Metadata contains a reference that cannot be resolved: 'http://172.19.111.72:9999/'.    There was no endpoint listening at http://172.19.111.72:9999/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.    Unable to connect to the remote server    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.19.111.72:9999HTTP GET Error    URI: http://172.19.111.72:9999/    There was an error downloading 'http://172.19.111.72:9999/'.    Unable to connect to the remote server    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.19.111.72:9999
  </code></pre>
  
  <p>If I use localhost, I get a similar error.</p>
  
  <p>tl;dr:</p>
  
  <p>I have a WCF service in a Docker container, I cannot connect to it from the host machine.</p>