CS 352: Lab 3 - Ajax & Web Services
Student Learning Objectives
After completing Lab Assignment 3, students should be able to
- Create a Visual Studio 2008 Web Site that uses ASP.NET Ajax to access local Web Services
- Create and author a Web Service Methods that return lists of strings
- Add JavaScript event handlers and Ajax methods to provide access to your Web Service Methods
- Test and debug your Web Service and Ajax code with Visual Studio debugger
- Work cooperatively as a pair-programming team
Lab 3 Pair Programming Teams
| Team 1 | Team 2 | Team 3 | Team 4 | Team 5 |
| Liam | Brock | Samwise | Tom | Paul |
| Gary | Kevin | Ben | Gene | Trevor |
You may wish to review the basic pair programming guidelines before you begin.
- One team member (the driver) has control of the keyboard/mouse and actively implements the program
- The other team member (the navigator) continuously observes the work of the driver to identify tactical defects (syntactic and spelling errors, etc.) and also thinks strategically about the direction of the work
You should change roles with each iteration
Iteration 1
- Create a
Lab3 ASP.NET Web Site
- Add a new Web Service item named
CarService.asmx
- You Web Service will provide information about the cars available in the XML file Cars.xml through Ajax asynchronous calls
- Rather than returning XML nodes, your Web Methods will return names as lists of strings
- The starter code for your CarService class is available to copy and paste into your CarService.asmx file
- Add the code to implement the Web Methods
GetMakes() and GetModels(string)
Functional Tests
Test and debug your service.asmx service by running it with the VS debugger. Add breakpoints in your Web Methods to help with debugging.
Test 1: test your GetColors Web method with make = "Audi" and model = "S4". Expected return value is
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http: ... ">
<string>Silver</string>
<string>Metallic</string>
</ArrayOfString>
Test 2: test your GetModels Web method with make = "BMW". Expected return value is
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http: ... ">
<string>3 series</string>
<string>5 series</string>
<string>7 series</string>
</ArrayOfString>
Test 3: test your GetMakes Web method. Expected return value is
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http: ... ">
<string>Acura</string>
<string>Audi</string>
<string>BMW</string>
</ArrayOfString>
Iteration 2
Before beginning these Iteration 2, switch roles between driver and navigator.
- Add the HTML controls to
Default.aspx to duplicate the screen snapshots provided below
- Use only HTML controls (fieldset, legend, p, label, textbox, select, option, and input)
- Add an
asp:ScriptManager to reference your Web service
- Add an
onButtonClick JavaScript function to fill the car's color select options list with the available colors based on make and model
Functional Tests
Test and debug your Web Page
- To enable JavaScript debugging with Visual Studio in Internet Explorer
- In IE menus, choose Tools > Internet Options, Advanced Tab
- Uncheck Disable Script Debugging (IE) and (Other). Click OK
- To debug JavaScript with Firefox, use Firebug extension
- Visual Studio's debugger will not work with Firefox
- Test 1: BMW 5 series expected output: Yellow and Banana
- Test 2: Audi A6 expected output: Cyan
- Test 3: Acura Integra expected output: Green, Sea Green, Pale Green
- Test 4: Acura Apple expected output: nothing
Iteration 3
Before beginning Iteration 3, switch roles between driver and navigator.
- Replace the make and model input textboxes with HTML select elements as shown in the snapshot below
- Add a onload event handler to your HTML body element to initialize the car's Make select option list to the list of string names returned by the Web Method
- Use Ajax to call your
GetMakes Web Method
- Test this in the browser and get it working
- Once working, modify your JavaScript
onGetMakesSuccess method by adding the code to fill the car's Model select option list with the correct models (based on make)
- Use Ajax to call your
GetModels Web Method
- Test this in the browser and get it working
- Once working, modify your JavaScript
onGetModelsSuccess method by adding the code to fill the car's Color select option list with the correct colors (based on make and model)
- Use Ajax to call your
GetColors web method
- Test this in the browser and get it working
- Change the code for the button onclick event handler to display the values of the items select
Iteration 4
Before beginning Iteration 4, switch roles between driver and navigator.
- Add JavaScript event handlers to handle the car's Model select element's
onchange so that when the user changes the car's model, the correct colors appear
- Test this in the browser and get it working
- Add JavaScript event handlers to handle to handle the car's Make select element's so that when the user changes the car's make, the correct models and colors appear
- Test this in the browser and get it working
To Receive Credit
Lab 3 is due by the start of class on Monday
- If you finish during lab, get checked off for having completed the lab
- If you are unable to finish during lab, the lab assignment is due Friday. To receive credit:
- Agree on a time to meet with your pair programming partner to complete the lab
- Save your work in solution
U:\Labs\nnLab3 in one of your cs352 accounts where nn is your account number
- Print out a snapshot of
Default.aspx page as displayed in the browser
- Write both names on your printout
- Clearly write the account number where the work is saved on the printout
- You do not need to print out and submit your code files - they will be checked online