1. Trang chủ
  2. » Công Nghệ Thông Tin

Module 6: Using Web Services

40 402 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Using web services
Trường học Microsoft Corporation
Thể loại module
Năm xuất bản 2000
Thành phố Redmond
Định dạng
Số trang 40
Dung lượng 0,92 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In the lab, students will call a Web service from an ASP.NET page, and create a Web service using Microsoft Visual Basic.. To present the animation: Before, you start the animation, say

Trang 1

Contents

Overview 1

Calling a Web Service from a Browser 11

Calling a Web Service Using a Proxy 14

Creating a Simple Web Service Using Visual

Trang 2

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

Trang 3

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

Trang 4

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:

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

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

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

Trang 5

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

http://terraserver.microsoft.net/terraservice.htm 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

Trang 7

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®

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

Trang 8

# 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

Trang 9

The Need for Web Services

! Allow applications to communicate across the Internet

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

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

Trang 10

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.

Trang 11

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

Trang 12

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

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

Trang 13

Finding Existing Web Services

Web services

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

Trang 14

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 http://www.uddi.org/

Trang 15

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 http://www.gotdotnet.com/playground/services/browsercaps.aspx

! 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 http://terraserver.microsoft.net/CensusDoc.htm

! 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 http://terraserver.microsoft.net/terraservice.htm

Topic Objective

To list some real examples

of Web services

Lead-in

There are a number of

existing Web services that

you can use

Trang 16

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

Note: You can do part of this

demonstration with the

TerraServer service at

http://terraserver.microsoft.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

Trang 17

Calling a Web Service from a Browser

http://server/vroot/webservice.asmx

Because Web Services are accessible by using URLs, HTTP, and XML, programs running on any platform and in any language can access them

Once you know the base URL for a Web service (the URL to the asmx file that

is the base of the Web service), you can use this URL to access a Web page known as the HTML description page The HTML description page provides information about what a Web service does, the methods it contains and their parameters, and its response type In addition, you can use the description page

to test the functionality of the Web service

For example, suppose you are accessing a Web service called hotel_Full.asmx, which is used to retrieve details from a hotel You know the base URL for this service is http://localhost/conference/hotel_full.asmx Entering the base URL with no extensions or parameters would produce a page that displays

information about the service and the methods it contains

Topic Objective

To describe how to call a

Web service from a

browser

Lead-in

One way of calling a Web

service is by accessing its

URL from the browser

Trang 18

<<need to get a new screen shot showing WSDL Contract>>

In addition to viewing information about the Web service in the browser, you can obtain a more formal definition of the Web service by viewing its Service Description Language (SDL) contract A link at the top of the description page allows you to view the contract, which contains an XML description of the Web service and its contents You can use this file to generate a proxy manually

WSDL Contract

The WSDL contract is an XML document written in an XML grammar called Web Service Description Language (WSDL) The document defines the format

of messages that the Web service understands The service description acts as

an agreement that defines the behavior of a Web service and instructs potential clients in how to interact with it

In addition to message format definitions and messaging patterns, the service description also contains the address that is associated with each Web service entry point The format of this address will depend on the protocol that is used

to access the service, such as a URL for HTTP or an e-mail address for SMTP

Trang 19

Calling a Web Service from a Browser (Continued)

! Pass the name of the method and all required parameters to the URL of the Web service

! Return value is in XML format

http://server/vroot/webservice.asmx/method?param=value

http://server/vroot/webservice.asmx/method?param=value

You can also call the methods of a Web service directly from a browser

To call a Web service method, pass the name of the method, the required parameters, and the parameters’ values to the URL of the Web service The Web service returns data in XML format when it is called from a Web browser

by using HTTP

For example, if a Web service named hotel_full has a method named Price that takes one parameter named strRoomType1, then you can call it directly from the browser by viewing the following URL:

http://localhost/conference/hotel_full.asmx/Price?strRoomType1=single The following XML is data that was returned from this URL If you want to use this kind of data in your Web application, you must parse it in a separate step

<?xml version="1.0"?>

<double xmlns="http://tempuri.org/">200</double>

Topic Objective

To describe how to call a

method of a Web service

from a browser

Lead-in

You can also call a method

of a web service directly

from the browser

Trang 20

# Calling a Web Service Using a Proxy

! Compiling an asmx File into a Proxy

! Compiling the Proxy into a DLL

! Calling Web Service Methods

Another method for calling a Web service is by using a proxy In this section, you will learn how to call a Web service by using a proxy

Topic Objective

To introduce the topics

included in this section

Lead-in

Another way of calling a

Web service by using a

proxy of the Web service

Ngày đăng: 05/11/2013, 12:15

TỪ KHÓA LIÊN QUAN