title: Hosting a Simple Wcf Service in Console
body: <p>I am trying to create a simple ConsoleApplication in which i would like to host a simple wcf service.</p>
  
  <p>Here is the code for my </p>
  
  <pre><code>namespace HostConsoleApplication
  {
      class Program
      {
          static void Main(string[] args)
          {
              using (System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(FirstWcfService.Service)))
              {
                  host.Open();
                  Console.WriteLine("Sai");
                  Console.ReadLine();
              }
          }
      }
  }
  </code></pre>
  
  <p>Then i have added an app.config which looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;system.serviceModel&gt;
          &lt;services&gt;
              &lt;service name="FirstWcfService.Service" behaviorConfiguration="ServiceBehavior"&gt;
                  &lt;endpoint address="FirstWcfService" binding="netTcpBinding" contract="FirstWcfService.IService"/&gt;
                  &lt;endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /&gt;
                  &lt;host&gt;
                      &lt;baseAddresses&gt;
                          &lt;add baseAddress="net.tcp://localhost:9101/"/&gt;
                      &lt;/baseAddresses&gt;
                  &lt;/host&gt;
              &lt;/service&gt;
          &lt;/services&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name="ServiceBehavior" &gt;
                      &lt;serviceMetadata httpGetEnabled="false" /&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
          &lt;/behaviors&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>When i run the host console app i get this exception:</p>
  
  <blockquote>
    <p>System.InvalidOperationException was
    unhandled   Message="Could not find a
    base address that matches scheme http
    for the endpoint with binding
    MetadataExchangeHttpBinding.
    Registered base address schemes are
    [net.tcp]."<br>
    Source="System.ServiceModel"<br>
    StackTrace:
           at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri
    relativeOrAbsoluteUri, Binding
    binding, UriSchemeKeyedCollection
    baseAddresses)
           at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase
    host, ServiceDescription description,
    ServiceElement serviceElement,
    Action`1 addBaseAddress)
           at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader
    configLoader, ServiceDescription
    description, ServiceElement
    serviceSection)
           at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader
    configLoader, ServiceDescription
    description, String configurationName)
           at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
           at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection
    baseAddresses)
           at System.ServiceModel.ServiceHost.InitializeDescription(Type
    serviceType, UriSchemeKeyedCollection
    baseAddresses)
           at System.ServiceModel.ServiceHost..ctor(Type
    serviceType, Uri[] baseAddresses)
           at HostConsoleApplication.Program.Main(String[]
    args) in C:\Documents and
    Settings\navin.pathuru\My
    Documents\Visual Studio
    2008\Projects\Solution2\HostConsoleApplication\Program.cs:line
    13
           at System.AppDomain._nExecuteAssembly(Assembly
    assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String
    assemblyFile, Evidence
    assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object
    state)
           at System.Threading.ExecutionContext.Run(ExecutionContext
    executionContext, ContextCallback
    callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
    InnerException:</p>
  </blockquote>
  
  <p>Just wondering if how to fix this.
  Thanks
  N</p>