Java Reference
In-Depth Information
1. Create a new project called CalcGUI , of type Windows Application. This will start you
off with a class called Form1.cs (.csis the file extension for C#). Change its name to
GUICalc.cs by right-clicking on it in the Solution Explorer.
2. Change the Text property of the form name to Calculator.
3. Add a label with the text “Enter numbers to add:”. You can add components to the form
by dragging them from the toolbox.
4. Users will need a place to enter the values the service will calculate, so add two text fields.
5. Add a button. Change the button text to “Get Result”. In the button's event handler, you'll
read the values from the text field and send them to the web service through your proxy.
6. Now you need a place to show the sum returned by the web service. Create another label,
make its text empty, and change its name to “labelResult”. Change its visibility to false
because when the GUI starts, you won't have a sum yet.
Now you should have a decent shell to start filling in your business logic.
In the Project dialog, click Add Existing Item, and then navigate to the location where you
saved your web service proxy. This will make your proxy class available to use in your GUI
class.
Before you can use the service, you need to tell the .NET project that you're going to invoke
a service proxy. Go to Project→Add Reference and add an assembly reference for the Sys-
tem.Web.Services namespace. This is similar to putting a JAR on your classpath, except
with a .dll.
Now switch to the source code view of GUICalc.cs , and add code so it looks like
Example 12-9 .
Example12-9.GUICalc.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//GUI that lets user add two integers
//by invoking web service
namespace CalcGUI
{
public partial class GUICalc : Form
Search WWH ::




Custom Search