This documentation is archived and is not being maintained.

Walkthrough: Accessing an XML Web Service with a Visual J# Web Forms Client

Visual Studio 2005

The following walkthrough describes the process for writing a simple Web Forms application using Visual J#. The application is a client for the XML Web service created in Walkthrough: Creating an XML Web Service with Visual J#. This walkthrough assumes you have completed the XML Web service walkthrough.

Web Forms are ASP.NET components that let you create forms on Web pages that can present information on any browser, using any markup language, and use code on the server to implement application logic. For more information, see ASP.NET Web Pages (Visual Studio).

In the first part of this walkthrough, you will create the Web Forms client.

To create a Web Forms client using Visual J#

  1. From the File menu, point to New, and then click Web Site.

    The New Web Site dialog box appears.

  2. Click the ASP.NET Web Application icon.

  3. Select Visual J# from the Language box.

  4. Select HTTP in the Location box, if it is not already displayed in the box.

  5. In the Location box, type the name and the location of the Web application. Specify VJSharpWebForms as the application name. By default, the project uses your local machine, "http://localhost" as the address of the Web application.

  6. Click OK.

    The Visual Studio template creates a solution for you. The project template adds a template file, default.aspx, to the project and opens this file in Design view. The default template contains a Form control. The project template also creates the code-behind file, Web.Config.

  7. Open the Toolbox, and drag a Label and a Button control to the design surface.

    The Label1 and Button1 controls are created.

  8. Change the text property of the button to read Click Here.

  9. Double-click the button.

    The Button1_Click event handler is created, and the Code Editor opens.

  10. Insert the following code in the body of the event handler:

    Label1.set_Text ("Hello World");
    
  11. Click Start Without Debugging on the Debug menu to run the project.

    The project builds and Internet Explorer opens the resulting Web page with this URL:

    http://localhost/VJSharpWebForms/default.aspx
    
  12. Click the Click Here button on the form.

    The label's text changes to "Hello World."

In this part of the walkthrough, you will consume the XML Web service created in Walkthrough: Creating an XML Web Service with Visual J#.

To consume the XML Web service

  1. In Solution Explorer, right-click the References node of the VJSharpWebForms project, and then click Add Web Reference.

    The Add Web Reference dialog box opens.

  2. Type the following Web service address in the URL box, and then click Go:

    http://localhost/VJSharpWebService/Service.asmx
    

    This is the URI of the Web service you created in Walkthrough: Creating an XML Web Service with Visual J#. The HelloWorld Web services method appears in the left pane of the Add Web Reference dialog box.

    NoteNote

    :   As an alternative to writing the Web service address in the URL box, you can choose to browse to the specific Web service by selecting the option Web Services on the local machine from the Add Web Dereference dialog box.

  3. Click Add Reference.

    A proxy class is generated for the VJSharpWebService Web service and is added to the project. Web services methods can now be invoked as if they were locally defined methods. The proxy class routes the Web services method calls to the Web services server, using SOAP over HTTP transport.

  4. Click the file default.aspx, and select View Designer to return to the design surface.

  5. Open the Toolbox, click the Standard tab, and drag another label to the design surface.

    The Label2 control is created.

  6. Double-click the Click Here button.

    The Code Editor opens.

  7. Add these lines to the body of the event handler Button1_Click:

    // Visual J#
    localhost.Service service = new localhost.Service();
    Label2.set_Text(service.HelloWorld());
    
  8. Press F5 to run the project.

    The project builds and Internet Explorer opens the resulting Web page.

  9. Click the Click Here button on the form.

    Both labels display the text "Hello World."

Show: