you need to host the service in the process and then debug it from there. It can be as simple as writing a console application to host the service, or writing a Windows service to host the service, or an application for Windows forms, or host it in IIS.
you can place in a console application like this:
static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(YourNamespace.YourServiceInterface))) { host.AddServiceEndpoint(typeof( YourNamespace.YourServiceInterface), new NetTcpBinding(), "net.tcp://localhost:9000/YourService"); host.Open(); Console.WriteLine("Press <Enter> to terminate the Host application."); Console.WriteLine(); Console.ReadLine(); } }
This article shows how to host a Windows service. I would recommend adding
Debugger.Launch();
as the first line in the OnStart method so that you can attach a debugger when the service starts. This will help debug any startup problems. Otherwise, you can simply select AttachToProcess from the Debug menu and connect to a running Windows service.
you need to add using System.Diagnostics to use the Debugger.Launch(); method Debugger.Launch();
source share