简体   繁体   English

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

[英]Service Broker / External Application Activation and Visual Studio Debugging

I just got moved to a code-base that uses a lot of Service Broker functionality. 我刚刚转到使用很多Service Broker功能的代码库。

My EAService.config is setup as below 我的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>   

My issue comes when I try to debug the above code. 我尝试调试上述代码时遇到了问题。

Since the Service Broker External Activator (C:\\Program Files\\Service Broker\\External Activator\\Bin\\ssbeas.exe) is instantiating the code....this is not something (to my best knowledge) that I can run in "Debug Mode" to wait for the call to come in and have a breakpoint set. 由于Service Broker外部激活程序(C:\\ Program Files \\ Service Broker \\ External Activator \\ Bin \\ ssbeas.exe)实例化了代码。...据我所知,这不是我可以在“调试”中运行的东西。模式”以等待呼叫进入并设置断点。

For example, with a WEBAPI project, I can do the traditional Start/Debug, and put a breakpoint on the ApiController/Method, and when a request comes in, it will break on the breakpoint, and I can pick up the debugging from there. 例如,对于一个WEBAPI项目,我可以执行传统的Start / Debug,并在ApiController / Method上放置一个断点,当一个请求进入时,它会在该断点处中断,我可以从那里进行调试。 。

With Service Broker, it is instantiating some .exe....and the .exe may open and close so quickly, and I cannot "search and find" to attach a debugger to it. 使用Service Broker,它正在实例化某些.exe ....,并且.exe​​可能会如此快速地打开和关闭,而我无法“搜索并找到”将调试器附加到该文件。

I also thought, "Maybe I'll have Service Broker send messages to a WCF service", but that looks like it is not possible or very cumbersome to implement, based on what I read at this SOF post: 我还以为“也许我会让Service Broker将消息发送到WCF服务”,但是根据我在此SOF帖子中所读到的内容,实现起来似乎是不可能或非常麻烦的:

Service Broker and WCF interoperability Service Broker和WCF的互操作性

Is there anyway for me to do the above setup in EAService.config AND get the debugger to break as seen in the image below? 无论如何,我是否需要在EAService.config中进行上述设置,并使调试器中断,如下图所示?

Or has anyone figured out a non hacky way to debug the C# code that is "activated" by Service Broker? 还是有人发现了一种非hacky的方式来调试由Service Broker“激活”的C#代码?

简单控制台应用程序

You have several options: 您有几种选择:

A. Modify the EAConfig to launch the program under debugger: A.修改EAConfig以在调试器下启动程序:

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

B. Use GFlags image execution options to add a debugger to your app B.使用GFlags映像执行选项将调试器添加到您的应用程序
C. Launch debugger from the app itself with Debugger.Launch() C.使用Debugger.Launch()从应用程序本身启动调试Debugger.Launch()
D. Disable EA and run the application directly from VS (F5), for debugging purposes, then enable EA back. D.禁用EA并直接从VS(F5)运行应用程序以进行调试,然后启用EA。

So this is what I ended up with...as the most consistent method I could find. 因此,这就是我最终找到的……这是我能找到的最一致的方法。

    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>

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

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