Export (0) Print
Expand All

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

Visual Studio 2005

The following walkthrough describes the process for writing a simple Windows Form 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.

First, you will create the client and add a Web reference to the XML Web service. Then, you modify the client's user interface so that the client can invoke the XML Web service. You can then build and test the client

To create a Windows application accessing an XML Web service client

  1. On the File menu, click Open Project/Solution.

    The Open Solution dialog box appears.

  2. Select the VJSharpWebService solution, and click Open.

  3. In Solution Explorer, right-click the solution root VJSharpWebService, point to Add, and then click New Project.

    The Add New Project dialog box appears.

  4. Select the Visual J# from Project Types, and select the Windows Application icon.

  5. In the Name box, type VJSharpWinClient.

  6. Click OK.

    The project template creates the VJSharpWinClient project, and opens the Windows Forms Designer.

  7. In Solution Explorer, right-click the project node VJSharpWinClient, and then click Set as Startup Project.

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

    The Add Web Reference dialog box opens.

  9. 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 service 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.

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

The next task is to modify the client's user interface so that the client can invoke the XML Web service. You can then build and test the client.

To modify the client's user interface

  1. Open the Toolbox, and drag a label and a button control to Form1.

    The label1 and button1 controls are created.

  2. Change the text property of button1 to read Click Here.

  3. Double-click the Click Here button.

    The button1_Click event handler is created in the Form1.jsl source file. The Code Editor opens.

  4. Replace the body of the event handler with the following code:

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

    The project builds and executes.

  6. Click button1 on the form.

    The label1 text changes to "Hello World".

Community Additions

ADD
Show:
© 2014 Microsoft