WCF Service running in ServiceHost (Console App)

J Thorpe picture J Thorpe · Apr 30, 2012 · Viewed 7.3k times · Source

I am attempting to wrap a WCF service that was previously running in an .asmx service in the taskbar into a Console App.

Here is the code for wrapping up the WCF Service:

class Program
{
    static void Main(string[] args)
    {
        Uri uri = new Uri("http://localhost:5000");

        using (ServiceHost host = new ServiceHost(typeof(CheckoutService), uri))
        {
                Console.WriteLine("Prepping CheckoutService server");
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                host.Open();

                Console.Clear();
                Console.WriteLine("CheckoutService server up and running");
                Console.WriteLine("Press Return to stop service at any point");
                Console.ReadLine();
                host.Close();
        }
    }

However, the client application that should receive this service (which used to work before the service was wrapped into a console app) is now crashing out with the error:

There was no endpoint listening at http://localhost:5000/CheckoutService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The endpoint configuration for this client in app.config is:

<endpoint 
    address="http://localhost:5000/CheckoutService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutService"
    contract="CheckoutServiceServer.ICheckoutService" name="BasicHttpBinding_ICheckoutService" />

I think perhaps I am missing some form of .config file in the console project hosting the WCF service but i could be wrong!

Answer

empi picture empi · Apr 30, 2012

It looks like you're closing the host without waiting for user input. Are you missing Console.ReadLine()?