How to use the enhanced debugger in Visual Studio .NET or in Visual Studio 2005 for cross-process debugging (317860)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition

This article was previously published under Q317860

SUMMARY

This step-by-step article explains how to create a small Web Service application in Visual Basic .NET or Visual Basic 2005, set a breakpoint in the application, and then attach to the ASP.NET worker process to debug your Web Service application. These tasks illustrate the new cross-process capabilities of the Visual Studio .NET debugger.

Note The information in this article applies to Visual Studio .NET or Visual Studio 2005.

Requirements

The following items describe the recommended hardware, software, network infrastructure, skills and knowledge, and service packs you will need:
  • Microsoft Windows Server 2003, Microsoft Windows 2000 Professional (or Server), or Microsoft Windows XP Professional with the .NET Framework installed
  • Microsoft SQL Server 7.0 with the Northwind database
  • Microsoft Visual Studio .NET or Microsoft Visual Studio 2005
Applies To:
  • Visual Studio.NET or Visual Studio 2005
  • ASP.NET

Use the enhanced debugger in Visual Studio .NET or Visual Studio 2005

The following steps show you how to create a small Web Service application in Visual Basic .NET or Visual Basic 2005, verify that the application works, set a breakpoint in the application, and then attach to the ASP .NET worker process to debug the application:
  1. On the Start menu, point to Programs, point to Microsoft Visual Studio .NET or Microsoft Visual Studio 2005, and then click Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the Start Page, click New Project.
  3. In the New Project dialog box, click Visual Basic Projects under Project Types, and then click ASP .NET Web Service under Templates.

    Note In Visual Studio 2005, click New on the File menu, click Web site, click ASP.NET Web Service under Templates, and then click Visual Basic in the language listbox.
  4. In the Location field, replace WebService1 with HowToService. Click OK.
  5. Service1.asmx.vb [Design] should be open in the Code Editor window. Right-click Service1.asmx.vb, and then click View Code.

    At the top, type Imports System.Data.SqlClient. This command enables you to access Classes in the associated namespace by using shorthand notation.
  6. Under the comments, add the following Function, which has been marked as a WebMethod for use in the Web Service:
    <WebMethod()> Public Function Orders(ByVal CustomerID As String) As DataSet
    Dim sqlConn As New SqlConnection("server=localhost;uid=sa;password=<Password>;database=northwind")
            sqlConn.Open()
    Dim sqlDA As New SqlDataAdapter("select * from orders where customerid = '" + CustomerID + "'", sqlConn)
            Dim ds As New DataSet("Orders")
            sqlDA.Fill(ds)
            Orders = ds
        End Function
    					
    Note <Password> represents the pasword of the sa account.
This project is now a fully functional Web Service.

Complete code listing (Service1.asmx.vb)

Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Data

<WebService(Namespace := "http://tempuri.org/")> _
Public Class Service1
    Inherits System.Web.Services.WebService

#Region " Web Services Designer Generated Code "

    Public Sub New()
        MyBase.New()

        'The Web Services Designer requires this call.
        InitializeComponent()

        'Add your own initialization code after the InitializeComponent call.

    End Sub

    'The Web Services Designer requires the following:
    Private components As System.ComponentModel.IContainer

    'NOTE: The Web Services Designer requires the following procedure. 
    'You can use the Web Services Designer to modify the procedure.  
    'Do not use the code editor to modify the procedure.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        'CODEGEN: The Web Services Designer requires this procedure.
        'Do not use the code editor to modify this procedure.
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

#End Region

    ' WEB SERVICE EXAMPLE
    ' The HelloWorld example service returns the string "Hello World".
    ' To build the HelloWorld example service, uncomment the following lines,
    ' and then save and build the project.
    ' To test this Web Service, make sure that the .asmx file is the start page,
    ' and then press F5.
    '
    '<WebMethod()> Public Function HelloWorld() As String
    '	HelloWorld = "Hello World"
    ' End Function

    <WebMethod()> Public Function Orders(ByVal CustomerID As String) As DataSet
        Dim sqlConn As New SqlConnection("server=localhost;uid=sa;password=<Password>;database=northwind")
        sqlConn.Open()
        Dim sqlDA As New SqlDataAdapter("select * from orders where customerid = '" + CustomerID + "'", sqlConn)
        Dim ds As New DataSet("Orders")
        sqlDA.Fill(ds)
        Orders = ds
    End Function

End Class
				

Verify that the service works

  1. Press F5 to run the application in debug mode. When Service1.asmx loads, click in the Address field of the browser to highlight the URL. Press CTRL+C to copy the URL. You will use the URL again in the "Next Steps" section.
  2. Click Orders. In the CustomerID field type alfki, and then click Invoke. Scroll through the XML to view the results.
  3. Close the browser to stop the debugger and return to Visual Studio .NET. Proceed to the "Next Steps" section of this article.

Next steps

  1. In the Code Editor window, position the cursor on the WebMethod declaration, and then press F9 to set a breakpoint.
  2. Press CTRL+ALT+P to open the Processes dialog box. In Available Processes, click aspnet_wp.exe. Click Attach. If you are running Internet Information Services 6.0 (IIS) in an IIS 6.0 process model, click w3wp.exe, and then click Attach.

    Note If you do not see this process, refer to the "Troubleshooting" section.
  3. If you are running Visual Studio .NET 2002 or Visual Studio .NET 2003, follow these steps:
    1. In the Attach to Process dialog box, click to select Common Language Runtime. Notice that HowToService is listed in the dialog box among the programs that will be debugged. (You may have more than one .NET-connected application running.) The listing should resemble the following:
      /LM/w3svc/1/root/HowToService-2-1265645....
    2. Click OK. Click Close.
  4. Click Start, click Run, and then type iexplore. Press CTRL+V to paste the Web Service address after the command. Click OK.
  5. When Service1.asmx loads, click Orders. In the CustomerID field, type alfki. Click Invoke.
  6. The application should break at the breakpoint. Press F11 to step into the code. In the debugging windows, click the Locals tab to monitor the values as you step through the code.
  7. Press F11 repeatedly to step through each line of code. When you step through the last line, the Web Service method executes and the XML results appear in your browser.

Troubleshooting

After you run the Web Service, if you cycled IIS and have not requested any ASP.NET pages, the aspnet_wp.exe worker process is not running. To restart the aspnet_wp.exe worker process, run the Web Service. The process appears in the Processes dialog box.

REFERENCES

For more information, refer to the following Microsoft Developer Network (MSDN) articles:

Modification Type:MinorLast Reviewed:8/25/2006
Keywords:kbvs2005applies kbvs2005swept kbHOWTOmaster KB317860 kbAudDeveloper