To use a WCF service, you need to host it in a runtime environment, so that the service host can listen for requests from clients, direct those requests to the service, and send responses back to the client. Using the host, you can start and stop the service.
If you want to self-host a service, you must create an instance of the System.ServiceModel.ServiceHost class and configure it with endpoints. This can be done in code or in a configuration file. Once the host is ready, any client can access the service by the URL specified.
Self-hosting can be done in any managed application, such as a console application, a Windows service, a Windows Forms application, or a Windows Presentation Foundation (WPF) application. In this recipe, we will learn how to self-host a WCF service in a console application and execute it.