简体   繁体   中英

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.

My EAService.config is setup as below

<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.

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.

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.

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 and WCF interoperability

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?

Or has anyone figured out a non hacky way to debug the C# code that is "activated" by Service Broker?

简单控制台应用程序

You have several options:

A. Modify the EAConfig to launch the program under debugger:

  <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
C. Launch debugger from the app itself with Debugger.Launch()
D. Disable EA and run the application directly from VS (F5), for debugging purposes, then enable EA back.

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>

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