如何从Web应用程序调试C#/.NET解决方案中的Web服务

问题描述:

我有一个应用程序解决方案,它由带有Web服务的C#/.NET中的八个项目组成.

I have an application solution consisting of eight projects in C#/.NET with Web services.

其中一个项目是Web服务.

One of the projects is of web services.

所有数据都是通过Windows Forms应用程序中的Web服务获取的.

All the data is fetched through the web services in a Windows Forms application.

但是在调试Windows应用程序时,我无法调试要求在Visual Studio 2010中获取数据的Web服务.

But while debugging my Windows application I am unable to debug the web services called for fetching the data in Visual Studio 2010.

当触发数据获取事件时,如何在解决方案中调试Web服务项目?

How do I debug a web services project in a solution when data fetching events are fired?

通常,在Visual Studio中进行调试时,所选的StartUp项目将以调试模式执行.在您的情况下,您需要启动和调试Web API项目以及WinForms项目.您可以通过右键单击解决方案资源管理器并选择设置启动项目来实现.将打开一个对话框,您可以在其中选择多个启动项目,然后选择调试解决方案时要启动的项目.

Normally, when debugging in Visual Studio the selected StartUp project will be executed in debug mode. In your case you need to start and debug both the Web API project as well as the WinForms project. You can do that by right-clicking in the solution explorer and selecting Set StartUp Projects. A dialog box opens where you can select Multiple startup projects and then select which projects to start when debugging the solution.

另一种选择是拥有一个StartUp项目(Web API项目,因为这是运行其他项目的要求).然后,您可以在解决方案资源管理器中右键单击WinForms项目,然后选择 Debug -> 启动新实例.您可以多次执行此操作,以调试同一项目的多个实例.

Another option is to have a single StartUp project (the Web API project as this is a requirement for the other project to run). You can then right-click on the WinForms project in the solution explorer and select Debug -> Start new instance. You can do this multiple times to debug multiple instances of the same project.

很显然,您始终可以将调试器附加到任何正在运行的进程,并且如果使用IIS部署Web API,该调试器将已经在运行.使用上面概述的过程,Visual Studio将附加到正确的工作进程.

Obviously, you can always attach the debugger to any running process and if your Web API is deployed using IIS it will already be running. Using the procedure outlined above Visual Studio will attach to the right worker process.