title: Code Only WCF Hosting has "localhost" in the link to the wsdl
body: <p>I have a wcf service that I am self hosting in an console app.</p>
  
  <p>When I run the service and deploy it to a machine (call it MyWCFRunningMachine) I can go to the "You have created a service" page.  (http://MyWCFRunningMachine:8090/MyService).</p>
  
  <p>But then it gives a link to the wsdl page.  That link looks like this: http://<strong>localhost</strong>:8090/MyService?wsdl</p>
  
  <p>So when I click on that link it tries to connect to the service using my machine rather than MyWCFRunningMachine.  </p>
  
  <p>If I cold type in the path to the wsdl (http://MyWCFRunningMachine:8090/MyService?wsdl) then I see a wsdl in the browser.  But if I try to add a service reference I get this error:</p>
  
  <blockquote>
    <p>The document was understood, but it could not be processed.<br>
      - The WSDL document contains links that could not be resolved.<br>
      - There was an error downloading 'http://<strong>localhost</strong>:8090/MyService?xsd=xsd0'.</p>
  </blockquote>
  
  <p>This is also referencing localhost when it should not.</p>
  
  <p>Here is the code I am using to self host my service:</p>
  
  <pre><code>public class SelfServiceHost
  {
      static string StartUpUrl {get{return "http://localhost:8090/MyService";}}
      static void Main(string[] args) { StartupService(StartUpUrl); }
  
      public static ServiceHost StartupService(string startUpUrl)
      {
          //+ Setup the Service
          //Create a URI to serve as the base address
          Uri httpUrl = new Uri(startUpUrl);
          //Create ServiceHost
          ServiceHost host = new ServiceHost(typeof(MyService), httpUrl);
          //Add a service endpoint
          host.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "");
          //Enable metadata exchange
          ServiceMetadataBehavior serviceMetadataBehavior =  
               new ServiceMetadataBehavior {HttpGetEnabled = true};
          host.Description.Behaviors.Add(serviceMetadataBehavior);
  
          //! Turn on Debug.  Remove for production!
          host.Description.Behaviors.Remove(typeof (ServiceDebugBehavior));
          ServiceDebugBehavior serviceDebugBehavior = 
              new ServiceDebugBehavior {IncludeExceptionDetailInFaults = true};
          host.Description.Behaviors.Add(serviceDebugBehavior);
  
          //Start the Service
          host.Open();
          Console.WriteLine("Service is hosted at " + httpUrl);
          Console.ReadLine();
  
          return host;
      }
  }
  </code></pre>
  
  <p>How can I get this to remove the localhost?  (NOTE: I cannot hard code it to MyWCFRunningMachine.  This service will be run on several different machines.</p>
  
  <p>Do I need to go with a config file that I change as I move machines?  (I have stayed away from a config file because I did not want to set one up for my console app, but if it is the only way, then I will do it.)</p>