Walkthrough: Debugging an XML Web Service

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply Topic does not apply

Standard

Topic does not apply Topic does not apply Topic does not apply Topic applies

Pro and Team

Topic applies Topic applies Topic does not apply Topic applies

Table legend:

Topic applies

Applies

Topic does not apply

Does not apply

Topic applies but command hidden by default

Command or commands hidden by default.

The steps in this walkthrough will show you how to debug an XML Web service. You will learn how to start and stop execution and set breakpoints.

By default, the ASP.NET process, using either aspnet_wp.exe or w3wp.exe, runs under the ASP.NET account. Therefore, you must have Administrator privileges on the computer where ASP.NET runs in order to debug it. For more information, see ASP.NET Debugging: System Requirements.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Working with Settings.

Prerequisites

If you already have an solution open, close it.

To create and debug a Web service

  1. On the File menu, click New, and then click Web Site.

    The New Web Site dialog box appears.

  2. In the Templates pane, select ASP.NET Web Service. You can now specify a directory on your local computer, or a URL to a remote computer.

  3. In the Location drop-down list, select File System, and in the text box type the directory on your local computer where the Web service will be located.

  4. Specify a unique directory name, such as Website1.

    The Web service will have the same name as the directory. You can put the directory on a remote server, or explore other options by clicking Browse.

  5. In the Language drop-down list, select the language you will use.

  6. Click OK.

    Visual Studio creates a new project and displays code for Service.cs, a template.

  7. Click the margin next to the line:

    ' Visual Basic 
        Return "Hello World"
    

    -or-

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

  8. Verify that the Active Configuration is the Debug configuration.

  9. On the Debug menu, select Start or press F5.

  10. The Debugging Not Enabled dialog box appears. Select the Add a new Web.config file with debugging enabled option, and click OK.

  11. Internet Explorer opens, and displays the link Hello World.

  12. Click the Hello World link.

    A new page opens in Internet Explorer.

  13. On the new page, click Invoke.

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

  14. On the Debug menu, click Stop Debugging.

To attach to the Web service for debugging

  1. In Visual Studio, you can attach the debugger to a running process. The following procedure shows how to do this.

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

  3. On the Debug menu, select Start Without Debugging.

    The Web service starts to run under Internet Explorer, but the debugger is not attached.

  4. On the Debug menu, select Attach to Process. You can also click Attach to Process on the Tools menu.

  5. Click Show processes from all users.

    Note

    If you are debugging in a Terminal Services or Remote Desktop session, you must also select Show processes in all sessions.

  6. In the Available Processes pane, find WebDev.WebServer.EXE in the Process column, and then click it.

    The WebDev.WebServer.EXE process loads your code and displays it in Internet Explorer.

  7. Click Attach.

    You have attached the debugger to your running Web service.

  8. In Internet Explorer, click the line that says "Hello World".

    A new page opens.

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

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

See Also

Concepts

Debugging XML Web Services