Export (0) Print
Expand All

Walkthrough: Debugging an XML Web Service

The steps in this walkthrough will show you how to debug an ASP.NET Web service written in the C# programming language. It will show you how to start and stop execution and set breakpoints.

Note   By default, the ASP.NET process (aspnet_wp.exe for IIS 5.0 and 5.1 running on Windows 2000 and Windows XP or w3wp.exe for IIS 6 on Windows Server 2003) runs as a ASPNET process. As a result, you must have Administrator privileges on the machine where ASP.NET runs to debug it.

First, you must close any open solutions.

To prepare for this walkthrough

  • If you already have an open solution open, close it. (From the File menu, select Close Solution.)

Next, you will create a new XML Web service in Visual Basic.

To create and debug an XML Web service for this walkthrough

  1. From the File menu, choose New and click Project.

    The New Project dialog box appears.

  2. In the Project Types pane, select Visual Basic Projects or Visual C# Projects.
  3. In the Templates pane, select ASP.NET Web Service
  4. In the Name box, give the project a unique name, for example, Walkthrough_WebServiceDebug.
  5. Click OK.

    Visual Studio creates a new project and displays an empty designer.

  6. In the designer, click the link:
    click here to switch to code view
    
  7. Locate and uncomment the following code:
    ' Visual Basic
    <WebMethod()> _
    Public Function HelloWorld() As String
       Return "Hello World"
    End Function
    
    // C#
    [WebMethod]
    public string HelloWorld ()
    {
       return "Hello World";
    }
    
  8. Click the margin next to the line:
    ' Visual Basic 
       Return "Hello World"
    
    // C#
       return "Hello World";
    

    A red dot appears and the text on the line is highlighted in red. The red dot represents a breakpoint. When you run the application under the debugger, the debugger will break execution at that location when the code is hit. You can then view the state of your application and debug it. For more information, see Breakpoints.

  9. From the Debug menu select Start.
  10. Internet Explorer opens and displays the link:
    Hello World
    
  11. Click the "Hello World" link.

    A new page opens in Internet Explorer.

  12. On the new page, click the Invoke button.

    At this point, you will hit the breakpoint in Visual Studio. You can now evaluate variables in the Watch window, view locals and step through your code.

  13. From the Debug menu, choose Stop Debugging.

In Visual Studio .NET, you can attach the debugger to a running process. For most effective debugging, compile the executable as a Debug version with symbol files (PDB).

To attach to the XML Web service for debugging

  1. In the current project, click in the margin next to the line that contains the following code:
    ' Visual Basic 
       Return "Hello World"
    
    // C#
       return "Hello World";
    

    This sets a breakpoint. You should see a red dot appear in the margin and red highlighting on the line of code.

  2. From the Debug menu, select Start Without Debugging.

    The XML Web service starts running under Internet Explorer, but the debugger is not attached.

  3. From the Debug menu, select Processes. (You can also use Debug Processes from the Tools menu.)
  4. Select Show system processes.
    Note   If you are debugging in a Terminal Services or Remote Desktop session, you must also select Show processes in all sessions.
  5. In the Available Processes pane, find aspnet_wp.exe in the Process column and click it.

    The aspnet_wp.exe process is the process that loads your code and displays it in Internet Explorer.

  6. Click the Attach button.
  7. In the Attach to Process dialog box, select Common Language Runtime under Choose the project types you want to debug, then click OK.

    You have attached the debugger to your running windows form. Notice that your process has been added to the Debugged Process pane of the Processes dialog box.

  8. In the Processes dialog box, click Close.
  9. In Internet Explorer, click the line that says "Hello World".

    A new page opens.

  10. On the new page, click the Invoke button.

    At this point, you will hit the breakpoint in Visual Studio. You can now evaluate variables in the watch window, view locals and step through your code.

See Also

Debugging an ASP.NET Web Service

Show:
© 2015 Microsoft