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


Define and Implement the Web Service Operations and Attributes

Exercise

In this lab, using .NET you will create the web service project, define and implement the web service operations and then modify the attributes. The first operation performs the conversion from miles to kilometers and the second operation converts kilometers to miles. Each method has the Web Method attribute, which exposes these methods over the web. When users view the description of the web service, the Namespace, Name and Description attributes describe the web service.

Prerequisites

  • None

Objectives

  • Discover how to create web service operations.
  • Define and implement the web service operations
  • Define the web service attributes

Setup Tasks

Microsoft Visual Studio .NET 2003 is required for this lab - download it now
Microsoft IIS is required to be installed on your local machine - download it now

Create the web service project:

  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 ASP.NET Web Service.
  4. Change the project location from the default to http://localhost/MetricConvWS.
  5. Click Ok.

Tasks

  1. In the Solution Explorer pane, double-click the .asmx file (usually named Service1.asmx).
  2. Remove the default operation code and add the following operations:
        [WebMethod]
        public double mile2km(double miles){
        return (1.6093 * miles);
        }
        [WebMethod]
        public double km2mile(double kms){
        return (0.6214 * kms);
        }
  3. Add attributes to describe the Measurement Conversion web service.
  4. Place the following code fragment immediately before the MetricConvWS class definition.
        [WebService (
        Namespace="http://rim.net/",
            Name="Metric  Conversion Web Service in C#", Description="This web service converts 
            from/to metric " +“measurement system")
            ]

Check Your Work

Download the completed code (ASMX).

Additional Labs

Go to the next exercise in "Building a Measurement Conversion Web Service Using .NET", Compile, Publish and Test the Web Service.

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.