I have a WCF service and a console application (host). Host Code:

private static void StartHost() { Uri baseAddress = new Uri("http://localhost:8873/MyWCF/"); using (ServiceHost selfHost = new ServiceHost(typeof(MyWCF), baseAddress)) { selfHost.AddServiceEndpoint(typeof(WcfService.IMyWCF), new WSHttpBinding(), "MyWCF"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); selfHost.Open(); Console.WriteLine("Press <ENTER> to terminate service."); Console.ReadLine(); selfHost.Abort(); selfHost.Close(); } } 

It works, I can send messages to my service through the client application.

But if I press Enter and close the host, the WCF service continues to work! Requests from the client pass, responses are returned .. In the task manager, I see the IIS Express process running, in the tray in the list of running sites with IIS, I also see my service .. Why this happens, because I use the using construct and even call the Abort methods ( ) and Close () .. How can I completely stop the service? The problem is that the service uses some dll from the solution, the service does not "release" them. Thanks for any help, links

Client Code:

 Uri baseAddress = new Uri("http://localhost:8873/MyWCF/"); BasicHttpBinding binding = new BasicHttpBinding(); var wcf = ChannelFactory<IMyWCF>.CreateChannel(binding, new EndpointAddress(baseAddress)); 
  • one
    WCF-сервис и консольное приложение (хост) ... если я нажимаю Enter и закрываю хост, то WCF-служба продолжает работать - why should the service have to do with a console and the fact of its closing? - tym32167
  • @ tym32167, but the console application starts hosting this service, and closes it at the end of its work. Now I figured out and realized that this happens only when starting from VS in debug. When you run the exe from bin, IIS does not start at all. However, now the client can not reach the service, writes "Listening to" localhost: 8873 / MyWCF.svc "did not perform any endpoint that could accept the message." Although the browser successfully knocks on this address and it is clear that the service is working. - Badalov Badal
  • I did not change the client code, I’ll add it now to the body of the question - Badalov Badal
  • one
    I do not know what you are doing. Do you have a service, or a console, or IIS - but there is documentation , you watched it? For example, the section on Press Ctrl+F5 to run the service. ? - tym32167

0