views:

1075

answers:

1

I'm trying to debug a web service (Windows XP SP3, VS 2008, ASP.NET 2, VB.NET).

For most of it, if the asp.net worker process is already loaded, I can start the Windows form that calls the web service, attach to aspnet_wp.exe in Visual Studio, and then debug to my heart's content, but catching the Application Start event in global.asax is a pain.

If I reset IIS, of course there is no process to attach to, until the Application start event is all over.

The only way I've found to do this is create a separate aspx page, set it as the start page, and run that - then I can stop on the break in the App start event, but it's a nuisance having to maintain a page that's essentially just a test stub.

Any ideas for something a bit neater? Kind of, "Attach to a process as soon as it starts".

Better still, of course, would be not to have to attach explicitly to aspnet_wp.exe in order to be able to debug the web service, but I haven't found a way of doing that either.

Thanks for any suggestions.

+3  A: 

Try sticking this in your Application Start event, it should kick your debugger everytime. Just make sure you take it out when you're done :-).

System.Diagnostics.Debugger.Launch()

Or better yet, in the OnStart of your WebService:

Protected Overrides Sub OnStart(ByVal args() As String)
    ' Add code here to start your service. This method should set things
    ' in motion so your service can do its work.
    System.Diagnostics.Debugger.Launch()
End Sub

Update: Adding this comment to the answer since it's a good idea:

Wrap this in #if DEBUG and it's a bit safer (won't end up slipping something so catastrophic into test/production environments). – sliderhouserules

brendan
Well it certainly launches the debugger! Thanks for that.. I was hoping for something a bit less drastic, but hopefully I won't need to debug the App_Start event too often, so taking that line out won't be too much of a chore.
ChrisA
Wrap this in #if DEBUG and it's a bit safer (won't end up slipping something so catastrophic into test/production environments).
sliderhouserules