Add the Sales Service
Purpose:
This process will create the class in the Web services project that will
actually deliver the service.
Starting Point:
You have the Northwind solution open. The Web services project has been
added to the solution and is selected.
Steps:
- Choose ‘Add Web Service’ from the Project menu.
- Name the new service "SalesService" and save it..
- When the Designer appears, press F7 to bring up the
Code window. Note that the new class inherits from
System.Web.Services.WebService.
- Expand the Component Designer Generated Code region
and examine the code it contains. Note that the class implements a
Dispose method specified in its parent's class. Collapse the region
after reading the code.
- Examine the sample Web method. Uncomment it and
compile in debug mode. Set a break point, make the Web services
project the start-up project, and step through to see how the sample method
works. This will familiarize you with the basic process and the form
of the output.
- Create a Web method to deliver the Region dataset, as
provided by the public static method in your Region. The method should
look something like this:
[WebMethod(Description="This method returns the dataset containing all of
the columns for all of the regions.")]
public DataSet theRegions()
{
return Region.theDataset();
}
- Add another method to deliver the region name (RegionDescription)
to a user that provides the Region ID. That should look something like
this:
[WebMethod(Description="This method returns the name (description) of the
region when passed the Region ID.")]
public string theRegionName(int idOfRegion)
{
Region myRegion = new Region(idOfRegion);
return myRegion.RegionDescription.Trim();
}
- Compile and save, test and debug.
Rationale:
It's what we need.
Discussion:
Once you have built the business objects you need for a Web application,
building a Web service is simply a matter of deciding which capabilities you
want to deliver, then encasing those capabilities in a properly decorated Web
method.
Previous Step: Add an Admin Home Page
Next Step: To Be Decided