Contents
Overview 1
Lesson: Building and Consuming a Web
Service That Returns Data 2
Review 15
Lab 7.1: Troubleshooting an ADO.NET
Application 16
Course Evaluation 25
Module 7: Building and
Consuming a Web Service
That Uses ADO.NET
Information in this document, including URL and other Internet Web site references, is subject to
change without notice. Unless otherwise noted, the example companies, organizations, products,
domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious,
and no association with any real company, organization, product, domain name, e-mail address,
logo, person, places or events is intended or should be inferred. Complying with all applicable
copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part
of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted
in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or
for any purpose, without the express written permission of Microsoft Corporation.
Troubleshoot errors in a Microsoft
®
ADO.NET application. The lab for this module is optional.
To teach this module, you need the following materials:
!
Microsoft PowerPoint
®
file 2389B_07.ppt
!
Module 7, “Building and Consuming a Web Service That Uses ADO.NET”
!
Lab 7.1, “Debugging a Windows Application and an XML Web Service
That Uses ADO.NET”
To prepare for this module:
!
Read all of the materials for this module.
!
Complete the practices and labs.
!
Read the latest .NET Development news at
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contenti
d=28000519
This module contains code examples that are linked to text hyperlinks at the
bottom of PowerPoint slides. These examples enable you to teach from code
the student computers.
Remind the students that they must use SQL Server Query Analyzer to run the
SQL script named lab6setup.sql in the Lab06_1 folder on the student
computers. This will ensure that all of the correct stored procedures for this lab
have been created.
The application is not designed to be a complete production quality app.
The design of the app assumes that if the user adds a new customer they will
have to add an order for that customer too. If they do not, there is no way to
cause that customer to appear in the initial Customers grid on refresh because
the select statement for that grid is based on EmployeeID. Without Order
information associated with the added Customer there is no EmployeeID
associated to select on.
Classroom lab setup
Note
Module 7: Building and Consuming a Web Service That Uses ADO.NET v How to Teach This Module
This section contains information that will help you to teach this module.
Lesson: Building and Consuming a Web Service That Returns Data
This section describes the instructional methods for teaching each topic in this
lesson.
Technical Notes: This lesson describes a Web service as an application
component. You should stress that Web services accept XML as input and
generate XML as output. Keep this discussion at a high level.
Discussion Questions: Personalize the following questions to the background
Technical Notes: Stress that when you create a Web reference, you are
importing method and class definitions from the Web service into your local
project. If the Web service returns data as a DataSet rather than an XML
stream, you should use the XML Schema Definition (XSD) file defined in the
Web service to build a container for the returned data in the client application.
To call a Web method, you must create a variable that points to the Web
service. You can then use the Web methods as if they were local to your
project.
What Is a Web Service?
How to Build a Web
Service That Returns
Database Information
How to Consume a Web
Service
vi Module 7: Building and Consuming a Web Service That Uses ADO.NET Discussion Questions: Personalize the following questions to the background
of the students in your class.
!
What are some ways to find out the reference to Web services?
!
How do you use Universal Description, Discover, and Integration (UDDI)?
Transition to Practice Exercise: Now that you have seen examples of
consuming a Web service, you can practice consuming a Web service in a client
application. Instruct students to turn to the practice exercise at the end of this
topic in the student workbook.
Practice Solution: The solution for the client application is located in
\Program Files\Msdntrain\2389\Practices\Mod07\Lesson2\ClientList.
Module 7: Building and Consuming a Web Service That Uses ADO.NET 1 Overview
!
Building and Consuming a Web Service That Returns
Data
!
Lab 7.1: Troubleshooting an ADO.NET Application
*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
Web services allow applications to communicate regardless of operating system
or programming language. Web services can be implemented on any platform
and are defined through public standards organizations. Sharing data through
Web services allows the Web services to be independent of each other while
simultaneously enabling them to loosely link themselves into a collaborating
group that performs a particular task.
In this module, you will learn how to create a Web service that returns data.
After completing this module, you will be able to:
!
Build a Web service.
!
Consume a Web service in a client application.
!
Troubleshoot errors in a Microsoft® ADO.NET application.
Consume a Web service. Introduction
Lesson objectives
Module 7: Building and Consuming a Web Service That Uses ADO.NET 3 What Is a Web Service?
H
T
T
P
X
M
L
XML
!
Programmable logic accessible through standard
Web protocols
Web
Service
Client
Web
Service
Web
Service
XML
.NET My Services
Web
Internet, using a standard transport protocol such as HTTP, to the shipper’s
cost-calculation Web service. The message might provide the weight and
dimensions of a package, origin and destination locations, and other
information such as class of service. The shipper’s Web service would then
calculate the shipping charge by using the latest cost table, and then return this
amount to the calling application in a simple XML-based response message for
use in calculating the total charge to the customer.
Definition
Example
4 Module 7: Building and Consuming a Web Service That Uses ADO.NET How to Build a Web Service That Returns Database Information
!
Web services that return database information
typically:
"
Establish a connection to a data source
"
Define the structure of a Typed DataSet (by using an
.xsd file)
"
Create an empty instance of the Typed DataSet
"
Run a query or perform calculations, and fill the
DataSet; a DataAdapter is commonly used to fill the
DataSet
"
Return the DataSet to the client application for further
Introduction
Building a Web service
that returns data
Module 7: Building and Consuming a Web Service That Uses ADO.NET 5 The following example defines a Web method that takes a customer’s city as
input, queries the Customers table in the Northwind database, and returns a
DataSet with information about all of the customers in that city.
'Connect to the Northwind DataBase
Dim myCn as New SqlConnection()
myCn.ConnectionString = "data source=localhost;" & _
"initial catalog=Northwind;" & _
"integrated security=SSPI;persist " & _
"security info=false"
myCn.Open()
This example assumes that a SqlDataAdapter object has been defined with the
following parameterized query:
SELECT CustomerId, CompanyName, ContactName, Address, City,
Region, PostalCode, Country, Phone, Fax
FROM Customers
WHERE (City like @city) When you create parameterized queries by using the SqlDataAdapter
object, use named arguments to mark parameters.
Example
Note