简体   繁体   中英

Debug WCF service called by a windows service in C#

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?

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.

最好在调试模式下从Visual Studio Selfhost运行IIS中托管的服务器,并在Windows服务中使用它并独立调试。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM