How to make WCF hosting in a console application?

How to host my WCF class library in a console application? I have a WCF service in the class library and I wanted to test the service outside of my project using a test application (I have to do this outside of the project)

+3
source share
3 answers

Create a simple console application, add a link to your WCF service build, 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 ServiceHostand pass it the type of service (implementation) class, and then basically call .Open()it.

Console.ReadLine() , - ENTER, .

! (, app.config , )

+2

ServiceHost ( ). WCF, .

0

Source: https://habr.com/ru/post/1725868/


All Articles