Reputation: 2864
I have a Windows service that has been scheduled using Quartz.NET. I have to debug it. As I cannot debug the start method, I put a breakpoint on the Execute
method. I compiled my solution and installed this service using installutil /i Name of the exe
. Then I did Attach To Process
from the Debug menu of Visual Studio and attached that EXE.
When that service runs, it stops at that breakpoint. The code is as follows
using OA.FileProcessing.WinService.IngeoServiceReference;
public virtual void Execute(JobExecutionContext context)
{
IngeoClient ingeoclient = new IngeoClient();
ingeoclient.ShowIngeoData();
ingeoclient.UpdateIngeoData();
}
OA.FileProcessing.WinService.IngeoServiceReference
is a WCF service hosted on IIS on my machine only. The debugger does not step into:
ingeoclient.ShowIngeoData();
I tried adding aspnet_wp.exe
as a process but it says a debugger is already attached.
How can I debug this WCF service from my Windows service?
Upvotes: 3
Views: 1832
Reputation:
It's better to run a server hosted in IIS from Visual Studio Selfhost in debug mode and consume it in your Windows service and debug both independently.
Upvotes: 0
Reputation: 38367
There are a couple ways you could do this.
One way would be that I would create a console application project, and reference the exe of the service project(same way you would reference a DLL). Create a mock JobExecutionContext and call Execute from the Console application. Configure Visual Studio to startup both the WCF service and the mock Console Application: In Solution Explorer, right-click the solution name. Click Set Startup Projects. In the Solution Properties dialog box, select Multiple Startup Projects.
This will startup both the console mode application and the WCF application in debug mode. The console application calls into the Windows Service Execute method, which in turn calls your Service. Since everything is being run in debug mode you should have no problem with breakpoints.
The other option is to set the WCF service as a startup project, run it from visual studio in debug mode, and then configure your Windows Service to connect to it. With this method you will not be able to step through the Windows Service, but your breakpoints in the WCF service should work.
Upvotes: 1