tags:

views:

367

answers:

2

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?

+1  A: 

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.

AaronLS
I want to go with second method as all business logic in in business layer which is exposed through WCF service. How to configure windows service to connect to WCF Service
Rohit
Ask yourself how initially configured your windows service to connecto the WCF service. Whereever that configuration is at you need to change it for debugging. To find out the endpoint information for your WCF service in debug mode: When you run a WCF project in debug mode there is a systray icon that is the hosting process for the WCF service, and you can get the port number, and other endpoint information there.
AaronLS
A: 

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.

Izhar