tags:

views:

44

answers:

3

How do I host my WCF class library in a console app? I have a WCF service within a class library and I wanted to test the service outside my project with a test app.(I have to do it outside the project)

A: 

You may create ServiceHost in your console application with your existing service contract (from your class library). After the service is running, your test project can access your WCF Service as usual.

Anton Setiawan
A: 

Consider using the WCF Service Host application: http://msdn.microsoft.com/en-us/library/bb552363.aspx

You can simply point the host to your service class library and configuration file and it will host your service for you.

Ray Vernagus
A: 

Create a simple console app, add a reference to your WCF service assembly, and then basically write these few lines:

   static void Main(string[] args)
    {
        using (ServiceHost host = new ServiceHost(typeof(Namespace.YourWCFService)))
        {
            host.Open();

            Console.WriteLine("Service host running......");

            foreach (ServiceEndpoint sep in host.Description.Endpoints)
            {
                Console.WriteLine("  endpoint {0} ({1})", 
                                  sep.Address, sep.Binding.Name);
            }

            Console.ReadLine();

            host.Close();
        }
    }

All you do is instatiate a ServiceHost and pass it the type of a service (implementation) class, and then basically call .Open() on it.

The Console.ReadLine() just wait until someone presses ENTER and then terminates the service host.

That's all there is! (of course, you need to specify service address and bindings in a app.config for the service host console app for it to work)

marc_s