Tải bản đầy đủ (.pdf) (40 trang)

Module 6: Using Web Services

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (942.58 KB, 40 trang )








Contents
Overview 1
What is a Web Service? 2
Calling a Web Service from a Browser 11
Calling a Web Service Using a Proxy 14
Creating a Simple Web Service Using Visual
Basic 19
Creating and Calling a Web Service Using
Visual Studio.NET 23
Lab 6: Using Web Services 32
Review 33

Module 6: Using Web
Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only
means of access is electronic, permission to print one copy is hereby granted.



Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.

 2000 Microsoft Corporation. All rights reserved.

Microsoft, BackOffice, MS-DOS, Windows, Windows NT, <plus other appropriate product
names or titles. The publications specialist replaces this example list with the list of trademarks
provided by the copy editor. Microsoft is listed first, followed by all other Microsoft trademarks
in alphabetical order. > are either registered trademarks or trademarks of Microsoft Corporation
in the U.S.A. and/or other countries.

<The publications specialist inserts mention of specific, contractually obligated to, third-party
trademarks, provided by the copy editor>

Other product and company names mentioned herein may be the trademarks of their respective
owners.


Module 6: Using Web Services iii

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Instructor Notes
This module introduces the concept of Web services. Students will learn about
Web services, how to call and use a Web service in their application, and finally
create a Web service.
In the lab, students will call a Web service from an ASP.NET page, and create a

Web service using Microsoft Visual Basic.
After completing this module, students will be able to:
!
Explain the goal of Web services and how they fit in the Web architecture.
!
Describe the Web services execution model.

!
Call a Web service from a browser.
!
Call a Web service using a proxy.
!
Use the data returned by a Web service
!
Create a simple Web service using Visual Basic.

Materials and Preparation
This section provides the materials and preparation tasks that you need to teach
this module.
Required Materials
To teach this module, you need the following materials:
!
Microsoft
®
PowerPoint
®
file 2063A_06.ppt
!
Module 6, “Using Web Services” (2063A_06.doc)
!

Lab, “Using Web Services” (2063A_L06.doc)
!
Animation, "title" (2063A_06A001..)
!
Animation script

Preparation Tasks
To prepare for this module, you should:
!
Read all of the materials for this module.
!
Complete all the demonstrations.
!
Complete the lab.
!
Read the animation script.
!
Read up about Web services from the .NET SDK documentation.

Presentation:
100 Minutes

Lab:
60 Minutes
iv Module 6: Using Web Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Multimedia Presentation
This section provides multimedia presentation procedures that do not fit in the

margin notes or are not appropriate for the student notes.
Using Web Services
!
To present the animation:
Action Say this

Before, you start the animation, say this:
There are two ways of calling a Web service, directly
from the browser or using a proxy client. This animation
demonstrates these two ways of calling a Web service.
Click Direct Client To access a Web service directly from a browser, the
client simply specifies the URL to the Web service(.asmx
file). The protocol used here is HTTP.
After processing the request, the Server returns a
description page to the client that lists all the available
methods of the Web service requested by the client.
After the client discovers the methods of the Web
service, it invokes a particular Web service method.
The Server processes the request and returns the data to
the client in the XML format.
Click Proxy Client Another method is to use a proxy client. In this method,
the client issues a request to the server for a Web service.
The request is in the form of an .aspx page.
Upon receiving the request from the client, the server
parses and compiles the .aspx page.
The Server then invokes the proxy (which is instantiated
in the .aspx page) to call the Web service. The protocol
used here is XMLP. (Earlier known as SOAP)
The response is then sent back to the client in a format
that the client .aspx page can use. The proxy carries out

the data translation.

Module 6: Using Web Services v

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Module Strategy
Use the following strategy to present this module:
!
What is a Web Service?
Start the section by providing students with an overview and the need for
Web services. Next, run the animation on Web services, and explain the
whole architecture and process of using Web services.
When giving students examples of Web services, tell them that as of now
there aren't very many Web services that are available as of now.
The section ends with a demonstration of how to call the terra server Web
service. It might be good idea to visit the Web site at
for more information on the
purpose of this Web service.
!
Calling a Web Service from a Browser
Start this section with a discussion of the two ways in which you can call a
Web service. (Calling from a browser and using a proxy). Reiterate the
advantage of calling a Web service using a proxy over calling a Web service
from a browser.
!
Calling a Web Service Using a Proxy
This section is the most useful section in this module. So spend more time
teaching this section and explain the concept with small demonstrations.
(You would have already done all these steps when you call the Terraserver

Web service)
!
Creating a Simple Web Service Using Visual Basic
This section describes how to write a Web service. Use the demonstration to
explain this further.


Module 6: Using Web Services 1

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Overview
!
What Is a Web Service?
!
Calling a Web Service from a Browser
!
Calling a Web Service Using a Proxy
!
Creating a Simple Web Service Using Visual Basic
!
Creating and Calling a Web Service Using Visual
Studio.NET


By providing fast access to information the Web has helped facilitate better
communication within and between companies. For many organizations,
however, browsing data-driven pages has not fulfilled their business needs
sufficiently. Programmable Web sites that directly link organizations,
applications, services, and devices with one another would better meet these

needs.
Web services provide a simple, flexible, standards-based model for binding
applications together over the Internet that takes advantage of existing
infrastructure and applications. Web applications can easily be assembled using
locally developed services and existing services, regardless of which platforms,
development languages, or object models have been used to implement the
constituent services or applications.
After completing this module, you will be able to:
!
Explain the goal of Web services and how they fit into the Web architecture.
!
Describe the Web services execution model.

!
Call a Web service from a browser.
!
Call a Web service by using a proxy.
!
Use the data returned by a Web service
!
Create a simple Web service by using Microsoft
®
Visual Basic
®
.

Topic Objective
To provide an overview of
the module topics and
objectives.

Lead-in
In this module, you will learn
about Web services that are
supported by ASP.NET, a
unified Web development
platform that has grown
from Active Server Pages
(ASP) technology.
2 Module 6: Using Web Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

#
##
#

What is a Web Service?
!
The Need for Web Services
!
Web Services Execution Model
!
Finding Existing Web Services
!
Examples of Existing Web Services
!
Demonstration: Calling the TerraService Web Service


Web services provide a simple, flexible, standards-based model for binding

applications together over the Internet that takes advantage of existing
infrastructure and applications. In this section, you will learn about the need for
Web services and also learn about their architecture. You will also learn about
existing Web services and how to find them.
Topic Objective
To introduce the topics in
the section.
Lead-in
In this section, you will see
an overview of Web
services.
Module 6: Using Web Services 3

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

The Need for Web Services
!
Allow applications to communicate across the Internet
!
Language independent
!
Protocol independent
!
Platform independent
!
Stateless architecture


One of today's most pressing challenges for developers is application
integration. Application integration is the process of taking a group of

applications and turning them into easy-to-use Web applications, even if they
run on different operating systems, were created with different programming
languages, and were built with different object models.
Like components, Web services represent black-box functionality that can be
reused without worrying about how the service is implemented. Web services
provide well-defined interfaces (called contracts) that describe the services they
represent. Developers can assemble applications by using a combination of
remote services, local services, and custom code. For example, a company
might assemble an online store that uses the Microsoft
®
Passport service to
authenticate users, a third-party personalization service to adapt Web pages to
each user's preferences, a credit-card processing service, a sales tax service,
package-tracking services from each shipping company, an in-house catalog
service that connects to the company's internal inventory management
applications, and custom code to individualize the interface and make it unique.
Unlike current component technologies, however, Web services do not use
protocols that are specific to certain object models, such as Distributed
Component Object Model (DCOM), which requires specific, homogeneous
infrastructures on the computers that run the client and the server. Web services
communicate by using standard Web protocols and data formats, such as
Hypertext Transfer Protocol (HTTP), Extensible Markup Language (XML), and
Extensible Markup Language Protocol (XMLP). Any system that supports these
Web standards will be able to support Web services.
A Web service can be used internally by a single application, or it can be used
externally by many applications that access it through the Internet. Because it is
accessible through a standard interface, a Web service allows disparate systems
to work together. The Web services model is independent of languages,
platforms, and object models.
Topic Objective

To explain the need for Web
services.
Lead-in
Before learning to
implement Web services,
you should understand how
they fill some business
needs.
Delivery Tip
If students are unfamiliar
with the XMLP protocol,
describe it briefly.
4 Module 6: Using Web Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

The Web service model is supported by ASP.NET, which is a unified Web
development platform that has grown from Active Server Pages (ASP)
technology. The ASP.NET Web services model assumes a stateless service
architecture. Stateless architectures are generally more scalable than stateful
architectures. Each time a service request is received, a new object is created.
The request into a method call, and the object is destroyed once the method call
returns. Services can use the ASP.NET State Management services if they need
to maintain a state between requests
.

Module 6: Using Web Services 5

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY


Web Services Execution Model


The Web services execution model mainly involves two entities, the client and
the service provider.

The term "client" is often misinterpreted. In this sense, a client is a Web
browser that views the results of calling a Web service.

The slide illustration illustrates how Web services are used between a client and
the Web server. Each component has a specific role in the execution model.
Web Service
In the Web service model, the Web service developer:
1. Creates the .asmx file that includes the namespace, classes, properties, and
methods.
2. Declares methods as Web methods that can be accessed over the Internet.

The following is an example of a simple .asmx file:
<%@ WebService Language="VB" Class="MathService" %>

Imports System.Web.Services
Imports System

Class MathService
Public Function <WebMethod()> Add(int1 As Integer, int2 As
Integer) As Integer
return(int1 + int2)
End Function

End Class



Topic Objective
To describe the Web
services execution model.
Lead-in
The Web services model
has two main parts: a
service provider that creates
the service, and a client that
consumes the service
(creates the .aspx page)
Note
Delivery Tip
Don't discuss the details of
this Web service. This
example is only meant to
show how simple the code
for a Web service can be.
The following sections in
this module will cover the
details of creating create a
Web service.
6 Module 6: Using Web Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Client
In the Web service model, the client:
1. Calls the Web service from the browser to determine which methods are

available.
When you call a Web service from a browser, you access the description
page, which lists the methods that are included in the Web service. The
protocol that is used in this case is HTTP, and the data is returned as XML.
2. Calls a method of the Web service from the browser.
When you call a method of a Web service from a browser, the protocol that
is used is HTTP, and the data is returned as XML.

Web Server
You can also call methods of the Web service by using code on an ASP.NET
page. To call a Web service from an ASP.NET page, the developer must:
1. Find out which web services are available. This involves finding the
Uniform Resource Locator (URL) for the Web service.
2. Compile the .asmx file (Web service) into a proxy by using the
WebServiceUtil.exe utility. This creates a .vb or .cs file that contains source
code for the proxy.
3. Compile the proxy (the .vb or .cs file you created in the previous step) into a
dynamic-link library (DLL) file in the /bin directory of the Web site.
4. Open the ASP.NET Web page.
a. Create an instance of the proxy
b. Call the methods of the Web service
c. Use the data returned by the Web service.


As the illustration shows, the proxy resides on the same server as the
Web page (.aspx) that calls it. An advantage of using a proxy is that it translates
the returned data from the server into a data type that the .aspx page can use. If
you call a Web service method directly from an .aspx page without using a
proxy, you will receive the data in XML form, which must be parsed in another
step.


To learn more about the Web services execution model, view the Using Web
Services animation. Open the file 2063A_06A001.swf from the Media folder.

Delivery Tip
Tell students they will learn
more about these steps later
in this module.
Note
Delivery Tip
Run the Macromedia Flash
animation Using Web
Services.
(2063A_06A001.swf)

For details about how to run
and describe the animation,
see the Multimedia
Presentation section in the
Instructor Notes for this
module.
Module 6: Using Web Services 7

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Finding Existing Web Services
!
UDDI
$
Defines a way to publish and discover information about

Web services
$
Relies upon a distributed registry of businesses and their
service descriptions implemented in a common XML
format
!
Businesses individually register information about the
Web services using UDDI business registration
!
Business registry is a logically centralized, physically
distributed service with multiple root nodes that
replicate data


For a company, getting information about which business partners have Web
services, and finding specific information about the available Web services, is
very difficult. The Universal Description, Discovery and Integration (UDDI)
specifications define a way to publish and discover information about Web.
UDDI relies on a distributed registry of businesses and their service
descriptions that has been implemented in a common XML format. The UDDI
specification consists of several related documents and an XML schema that
defines an XMLP based programming protocol for registering and discovering
Web services.
The core component of UDDI is the UDDI business registration, an XML file
that is used to describe a business entity and its Web services. Conceptually, the
information provided in a UDDI business registration consists of three
components: “white pages”, which include address, contact, and known
identifiers; “yellow pages”, which include industrial categorizations that are
based on standard taxonomies; and “green pages”, which include the technical
information about the services that are exposed by the organization. Green

pages include references to specifications for Web services, as well as any
support that may be required for pointers to file and URL-based discovery
mechanisms.
Topic Objective
To describe how to find
existing Web services using
the Universal Description,
Discovery, and Integration
(UDDI) specification.
Lead-in
Web services are the next
step in the evolution of the
World Wide Web (WWW);
they allow you to place
programmable elements on
Web sites where others can
access distributed
behaviors. You can use
UDDI registries to promote
and discover distributed
Web services.
8 Module 6: Using Web Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Businesses individually register information about the Web services that they
expose for other businesses to use. This information can be added to the UDDI
business registry through a Web site, or by using tools that make use of the
programmatic service interfaces described in the UDDI programmer’s
application programming interface (API) specification. The UDDI business

registry is a logically centralized, physically distributed service with multiple
root nodes that replicate data with each other regularly. When a business
registers with a single instance of the business registry service, the service
shares the data automatically with other UDDI root nodes. After the data has
been distributed, it becomes freely available to anyone who needs to discover
which Web services are exposed by a particular business.
For more information about UDDI, go to the UDI Web site at

Module 6: Using Web Services 9

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Examples of Existing Web Services
!
.NET BrowserCaps Web service
!
Census.NET Web service
!
Microsoft TerraServer.NET Web service


The following are some real examples of Web services.
!
BrowserCaps Web service
The BrowserCaps Web service provides two levels of functionality. First, it
provides a convenient means to obtain a list (in the form of a DataSet) of all
user agent strings (by using the GetUserAgentList method), in their correct
hierarchical order. Second, the BrowserCaps Web service provides the
ability to fetch an enumeration of a particular user agent's capabilities,
formatted as an XML string (by using the GetBrowserCaps method).

For more information about the BrowserCaps Web service, go to

!
Census .NET Web Service
The Census .NET Web service provides programmable methods that access
data from the 1990 Census through the Internet.
For more information about the Census Web service, go to

!
Microsoft
®
TerraServer .NET Web service
The Microsoft TerraServer .NET Web service (also known as TerraService)
is a programmable interface to the Microsoft TerraServer online database of
high-resolution aerial imagery (in DOQ format) and scanned topographical
maps (in DRG format) from the United States Geological Survey. Using
Microsoft
®
.NET technologies, developers can easily incorporate imagery
and other data from the TerraServer into their web sites or .NET WinForm
applications.
For more information about the TerraService, go to


Topic Objective
To list some real examples
of Web services.
Lead-in
There are a number of
existing Web services that

you can use.
10 Module 6: Using Web Services

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Demonstration: Calling a Web Service


In this demonstration, you will see how to call the Microsoft TerraServer Web
Service.
Topic Objective
To demonstrate how to call
a Web Service.
Lead-in
In this demonstration, you
will see how to use a Web
service that performs math
operations in an ASP.NET
page.
Delivery Tip
1. View the SDL contract for
the MathService service at
http://localhost/2063/democ
ode/mod06/mathservice.as
mx.
2. Fill in parameters for the
Add method, then click
Invoke.
3. Build a proxy DLL for the
MathService by running

mkService.bat from a
command prompt.
4. Open the file
\\2063\democode\mod06\m
ath.aspx to show how to call
it from code.
5. View math.aspx in
Microsoft
®
Internet Explorer.

Note: You can do part of this
demonstration with the
TerraServer service at
rosoft.n
et/terraservice.asmx. You
can call the GetPlaceList
method with a parameter of
"seattle, 10, False". It does
not seem to work to call this
web service from an
ASP.NET page, however.

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×