Walkthrough: Accessing an XML Web Service with a Visual J# Windows Client
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
On the File menu, click Open Project/Solution.
The Open Solution dialog box appears.
Select the VJSharpWebService solution, and click Open.
In Solution Explorer, right-click the solution root VJSharpWebService, point to Add, and then click New Project.
The Add New Project dialog box appears.
Select the Visual J# from Project Types, and select the Windows Application icon.
In the Name box, type VJSharpWinClient.
The project template creates the VJSharpWinClient project, and opens the Windows Forms Designer.
In Solution Explorer, right-click the project node VJSharpWinClient, and then click Set as Startup Project.
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.
Type the following Web service address in the URL box, and then click Go:
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.
: 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.
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
Open the Toolbox, and drag a label and a button control to Form1.
The label1 and button1 controls are created.
Change the text property of button1 to read Click Here.
Double-click the Click Here button.
The button1_Click event handler is created in the Form1.jsl source file. The Code Editor opens.
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());
Press F5 to run the project.
The project builds and executes.
Click button1 on the form.
The label1 text changes to "Hello World".