Service Broker/外部应用程序激活和 Visual Studio 调试

Service Broker / External Application Activation and Visual Studio Debugging

我刚刚转到使用大量 Service Broker 功能的代码库。

我的EAService.config设置如下

<ApplicationService name="NotificationTest" enabled="true">
  <OnNotification>
    <ServerName>MyServer\MyInstance</ServerName>
    <DatabaseName>MyDatabase</DatabaseName>
    <SchemaName>dbo</SchemaName>
    <QueueName>MyQueueName</QueueName>
  </OnNotification>
  <LaunchInfo>
    <ImagePath>C:\SomeFolder\SomeConsoleApp.exe</ImagePath>
    <CmdLineArgs>myCommandLineArg1</CmdLineArgs>
    <WorkDir>C:\SomeFolder\</WorkDir>
  </LaunchInfo>
  <Concurrency min="1" max="1" />
</ApplicationService>   

当我尝试调试上述代码时出现问题。

由于 Service Broker External Activator (C:\Program Files\Service Broker\External Activator\Bin\ssbeas.exe) 正在实例化代码....这不是什么(尽我所能知识),我可以 运行 在 "Debug Mode" 中等待呼叫进入并设置断点。

比如一个WEBAPI项目,我可以做传统的Start/Debug,在ApiController/Method上打断点,当有请求进来的时候,就在断点处断,我可以从那里开始调试。

对于 Service Broker,它正在实例化一些 .exe....并且 .exe 可能会打开和关闭得如此之快,我无法 "search and find" 将调试器附加到它。

我也想过,"Maybe I'll have Service Broker send messages to a WCF service",但是根据我在这个 SOF post:

上读到的内容,这看起来是不可能的或者实施起来非常麻烦

Service Broker and WCF interoperability

我是否可以在 EAService.config 中进行上述设置并让调试器中断,如下图所示?

或者有没有人想出一个简单的方法来调试 Service Broker "activated" 的 C# 代码?

您有多种选择:

一个。修改 EAConfig 以在调试器下启动程序:

  <ImagePath>C:\PathToDebugger\YourDebuggerOfChoice.exe</ImagePath>
  <CmdLineArgs>C:\SomeFolder\SomeConsoleApp.exe myCommandLineArg1</CmdLineArgs>

乙。使用 GFlags 图像执行选项将调试器添加到您的应用程序
C. 使用 Debugger.Launch()
从应用程序本身启动调试器 D. 出于调试目的,直接从 VS (F5) 禁用 EA 和 运行 应用程序,然后重新启用 EA。

这就是我最终得到的……这是我能找到的最一致的方法。

    static void Main(string[] args)
    {

        try
        {

#if DEBUG
            int index = Array.FindIndex(args, x => x.Equals("LAUNCHDEBUGGER", StringComparison.OrdinalIgnoreCase));
            if (index > -1)
            {
                System.Diagnostics.Debugger.Launch();
            }
#endif

 <LaunchInfo>
    <ImagePath>C:\SomeFolder\SomeConsoleApp.exe</ImagePath>
    <CmdLineArgs>myCommandLineArg1 LAUNCHDEBUGGER</CmdLineArgs>
    <WorkDir>C:\SomeFolder\</WorkDir>
  </LaunchInfo>