title: How to programmatically generate WSDL from WCF service (Integration Testing)
body: <p>I am looking to write some integration tests to compare the WSDL generated by WCF services against previous (and published) versions. This is to ensure the service contracts don't differ from time of release.</p>
  
  <p>I would like my tests to be self contained and not rely on any external resources such as hosting on IIS.</p>
  
  <p>I am thinking that I could recreate my IIS hosting environment within the test with something like...</p>
  
  <pre><code>using (ServiceHost host = new ServiceHost(typeof(NSTest.HelloNS), new Uri("http://localhost:8000/Omega")))
  {
      host.AddServiceEndpoint(typeof(NSTest.IMy_NS), new BasicHttpBinding(), "Primary");
      ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
      behavior.HttpGetEnabled = true;
      host.Description.Behaviors.Add(behavior);
      host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
      host.Open();
  }
  </code></pre>
  
  <p>Does anyone else have any better ideas?</p>
  
  <p><strong>EDIT:</strong>
  Obviously this code is simply creating a host for the service, I am still missing the client code to obtain the WSDL definition.</p>