Microsoft KB Archive/317860

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

Article ID: 317860

Article Last Modified on 8/25/2006

-

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:  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. On the Start Page, click New Project. 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. In the Location field, replace WebService1 with HowToService. Click OK. 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.  Under the comments, add the following Function, which has been marked as a WebMethod for use in the Web Service:  Public Function Orders(ByVal CustomerID As String) As DataSet Dim sqlConn As New SqlConnection(&quot;server=localhost;uid=sa;password=<Password>;database=northwind&quot;) sqlConn.Open Dim sqlDA As New SqlDataAdapter(&quot;select * from orders where customerid = '&quot; + CustomerID + &quot;'&quot;, sqlConn) Dim ds As New DataSet(&quot;Orders&quot;) sqlDA.Fill(ds) Orders = ds   End Function Note  represents the pasword of the sa account. </li></ol>

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 := &quot;http://tempuri.org/&quot;)> _ Public Class Service1 Inherits System.Web.Services.WebService


 * 1) Region &quot; Web Services Designer Generated Code &quot;

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


 * 1) End Region

' WEB SERVICE EXAMPLE ' The HelloWorld example service returns the string &quot;Hello World&quot;. ' 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 = &quot;Hello World&quot; ' End Function

<WebMethod> Public Function Orders(ByVal CustomerID As String) As DataSet Dim sqlConn As New SqlConnection(&quot;server=localhost;uid=sa;password=<Password>;database=northwind&quot;) sqlConn.Open Dim sqlDA As New SqlDataAdapter(&quot;select * from orders where customerid = '&quot; + CustomerID + &quot;'&quot;, sqlConn) Dim ds As New DataSet(&quot;Orders&quot;) 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 &quot;Next Steps&quot; 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 &quot;Next Steps&quot; section of this article.

Next steps
<ol> In the Code Editor window, position the cursor on the WebMethod declaration, and then press F9 to set a breakpoint.</li> 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 &quot;Troubleshooting&quot; section.</li> If you are running Visual Studio .NET 2002 or Visual Studio .NET 2003, follow these steps: <ol style="list-style-type: lower-alpha;">  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: <pre class="fixed_text">/LM/w3svc/1/root/HowToService-2-1265645.... </li> Click OK. Click Close.</li></ol> </li> Click Start, click Run, and then type iexplore. Press CTRL+V to paste the Web Service address after the command. Click OK.</li> When Service1.asmx loads, click Orders. In the CustomerID field, type alfki. Click Invoke.</li> 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.</li> 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.</li></ol>

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.