RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Accessing an ASP.NET "Hello World" Web Services Application

If you want to consume the Web Services application you created, you must create a client application to access your ASP.NET Web Services application. This process requires different development steps to achieve the desired output.

To access a simple "Hello World" ASP.NET Web Services application

  1. Create a client application.
  2. Add a Web Reference for an XML web service.
  3. Create the code-behind logic.
  4. Run the client application.

To create a client application

  1. Choose FileNewOther. A New Items dialog box appears.
  2. Select any type of application to create your client, such as a Windows Forms application or an ASP.NET Web application. For this example, we will create a Windows Forms application (either Delphi for .NET or C#).
  3. Click OK. A New Project dialog box appears.

To add a Web Reference for an ASP.NET Web Services application

  1. Choose ProjectAdd Web Reference.
  2. From the CodeGear UDDI Browser web dialog box, enter the following URL in the address text box at the top:

http://localhost/WebService1/WebService1.asmx

Note: The name of your application may not be WebService1. In that case, use your own application name in place of WebService1 in the example preceding example.
  1. Press Enter.
    Note: If you need to determine the proper path and you are using IIS, you can open the IIS Administrator from the Windows XP Control Panel Administrative Tools. Find the WebService you have saved and compiled in the list of IIS web sites, then review the name of the site and the name of the .asmx
    file. If you have entered the proper path, this should display information about the WebMethods.
  2. Click the Service Description link to view the WSDL document.
  3. Click Add Reference to add the WSDL document to the client application. A Web References folder is added to the Project directory in the Project Manager which contains the WebService1.wsdl file and the dialog box disappears.

To create the code-behind logic

  1. Add a Button to the Windows Form.
  2. Double-click the Button to view the code-behind file.
  3. For a Delphi for .NET client, implement the Click event in the Code Editor with the following code:

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
    ws: TWebService1;
begin
                ws := TWebService1.Create;
                button1.Text := ws.HelloWorld();
end;

When you added the Web Reference to your application, RAD Studio used the WSDL to generate a proxy class representing the "Hello World" web service. The Click event uses methods from the proxy class to access the web service. For a Delphi for .NET client, you may need to add the unit name of the proxy class (for example, localhost.WebService1) to the uses clause of your Windows Form unit to prevent errors in your Click event.

  1. For a C# client, implement the Click event in the Code Editor with the following code:

    private void button1_Click(object sender, System.EventArgs e)
        {
                TWebService1 ws = new TWebService1();
                button1.Text = ws.HelloWorld();
        }
To run the client application

  1. Save the application.
  2. Compile and run the project.
  3. Click the Button on your client application. The "Hello World" caption appears on the button.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!