BlackBerry
Skip Top Navigation
Developers Partners
North America [change region] Products Solutions Purchasing Support
Developers


Create a Simple Microsoft Windows Application to Test the Web Service

Exercise

Create a Microsoft Windows application that uses the sample web service operations.

Prerequisites

Objectives

  • Discover how to create a Microsoft Windows application that uses web service operations.

Setup Tasks

This lab is dependent on the previous two labs. Simply downloading the completed code files from the previous labs and installing them on your IIS Server may not work due to IIS Server settings. To set up a web service project and define web service operations and attributes, see the lab entitled Define and implement the web service operations and attributes for more details. To compile, test and publish the web service see the lab entitled Compile, test and publish the web service.

Tasks

The complete sample code is available at the end of this section.

  1. In Microsoft Visual Studio .NET, on the File menu, click New > Project.
  2. In the Project Types tree, click the Visual C# Projects folder.
  3. In the Templates pane, click Windows Application.
  4. Change the project location to a local directory, for example, c:\temp\MetricConvWSTest
  5. Click OK.
  6. To create a web reference to the Measurement Conversion web service, in the Solution Explorer window, right-click the References tag.
  7. Click Add Web Reference.
  8. Type the path to the metric conversion web service at http://localhost/MetricConvWS/Service1.asmx.
  9. Click Go.
  10. When the web service is detected, click Add Reference.
  11. To add a button to test the web service, in the Toolbox pane, drag the Button control to the application form.
  12. Double-click the button.
  13. Add the following code to the button1_Click method:
  14.     private void button1_Click(object sender, System.EventArgs e)
    {
    localhost.MetricConversionWebServiceinC MyService =
    new localhost.MetricConversionWebServiceinC();
    System.Console.WriteLine("1 km = " + MyService.km2mile(1) + " miles");
    System.Console.WriteLine("1 mile = " + MyService.mile2km(1) + " kms");
    }

    Tip: Note that localhost is an identifier of the web reference that you created to the web service.

  15. To run the application, press F5 and click the button. The following test results display in the debug output panel:
        1 km = 0.6214 miles
    1 mile = 1.6093 kms

Check Your Work

Download the sample example WebForm1.aspx.cs from here.

Additional Labs

Back to the Developer Lab Main Menu

 
     
 Home | Products | Solutions | Purchasing | Support | Developers | Worldwide | News | About Us | Contact Us | Site Map
 Legal | Copyright © 2008 Research In Motion Limited, unless otherwise noted.