简体   繁体   English

如何使用WCF在C#中调试Localhost客户端/服务

[英]How To Debug Localhost Client/Service in C# with WCF

New to C#, I noticed that creating services isn't something you can run in the Visual Studio 2017 interface for debug and step it through. C#的新增功能,我注意到创建服务不是您可以在Visual Studio 2017界面中运行以进行调试和逐步完成的工作。 At least, not that I'm aware. 至少不是我所知道的。 Instead, you have to create the service as you want it, hope it works, then use the service installer command ( InstallUtil.exe ), and then yet you have no way to step it through for debug in order to check for issues. 相反,您必须根据需要创建服务,希望它能运行,然后使用服务安装程序命令( InstallUtil.exe ),然后您就无法单步调试它以检查问题。 Compound this problem with needing to work with a client EXE that needs to talk to the service EXE on localhost over Named Pipes IPC/RPC using WCF. 由于需要使用客户端EXE(需要使用WCF通过命名管道IPC / RPC与本地主机上的服务EXE进行对话)来解决此问题,因此使此问题更加复杂。

So, what's the proper way to debug this? 那么,调试此错误的正确方法是什么? Should I instead just build a regular console app first, get the client GUI EXE (a Win Forms app) to talk to this console app over WCF, and then, when that works, copy the code from the console app into the service app and install the service? 相反,我应该首先构建一个常规的控制台应用程序,还是让客户端GUI EXE(Win Forms应用程序)通过WCF与该控制台应用程序对话,然后在可行的情况下,将代码从控制台应用程序复制到服务应用程序中,安装服务?

  • In Solution Explorer, right-click the solution name. 在解决方案资源管理器中,右键单击解决方案名称。

  • Click Set Startup Projects. 单击设置启动项目。

  • In the Solution Properties dialog box, select Multiple Startup Projects. 在“解决方案属性”对话框中,选择“多个启动项目”。

  • In the Multiple Startup Projects grid, on the line that corresponds to the server project, click Action and choose Start. 在“多个启动项目”网格中,在与服务器项目相对应的行上,单击“操作”,然后选择“启动”。

  • On the line that corresponds to the client project, click Action and choose Start. 在与客户端项目相对应的行上,单击“操作”,然后选择“开始”。

  • Click OK. 单击确定。

for more information please visit https://msdn.microsoft.com/en-us/library/bb157685.aspx 有关更多信息,请访问https://msdn.microsoft.com/en-us/library/bb157685.aspx

creating services isn't something you can run in the Visual Studio 2017 interface for debug and step it through. 创建服务不是您可以在Visual Studio 2017界面中运行以进行调试并逐步完成的工作。 -You can debug as you debug C# or js for that matter. -您可以在调试C#或js时进行调试。

You can create your service alone completely and wcftestclient.exe to debug and test service alone. 您可以完全单独创建服务,也可以完全创建wcftestclient.exe来调试和测试服务。

So, what's the proper way to debug this? 那么,调试此错误的正确方法是什么? You can run wcftestclient.exe from Visual studio command prompt. 您可以从Visual Studio命令提示符下运行wcftestclient.exe。 Right click on My Service Projects and Add the baseaddress where you had hosted the service.Below are the snapshots. 右键单击我的服务项目,然后添加托管服务的基址。以下是快照。 在此处输入图片说明 Put a debugger in VS where you want to debug and provide the inputs from this client GUI.The debugger will be hit.So you dont have to create a console app or anything to test WCF service. 在您要调试的VS中放置一个调试器,并提供此客户端GUI的输入。调试器将被选中,因此您无需创建控制台应用程序或任何东西即可测试WCF服务。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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