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:
In Microsoft Visual Studio .NET, on the File Menu, click New > Project.
In the Project Types tree, click the Visual C# Projects folder.
In the Templates pane, click ASP.NET Web Service.
Change the project location from the default to http://localhost/MetricConvWS.
Click Ok.
Tasks
In the Solution Explorer pane, double-click the .asmx file (usually named Service1.asmx).
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);
}
Add attributes to describe the Measurement Conversion web service.
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")
]