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

Tài liệu Module 9: Implementing a Nonstandard Web Services doc

34 315 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 đề Implementing a Nonstandard Web Service
Trường học Microsoft Corporation
Chuyên ngành Web Services
Thể loại module
Năm xuất bản 2001
Thành phố Redmond
Định dạng
Số trang 34
Dung lượng 887,78 KB

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

Nội dung

Contents Overview 1 HTML Screen Scraping Web Services 2 Lab 9: Implementing an Aggregated Web Service 17 Review 28 Module 9: Implementing a Nonstandard Web Service... Explain how t

Trang 1

Contents

Overview 1

HTML Screen Scraping Web Services 2

Lab 9: Implementing an Aggregated Web

Service 17

Review 28

Module 9: Implementing

a Nonstandard Web Service

Trang 2

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 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

 2001 Microsoft Corporation All rights reserved

Microsoft, MS-DOS, Windows, Windows NT, Active Directory, Authenticode, Biztalk, Intellisense, Jscript, MSDN, PowerPoint, Visual Basic, Visual C++, Visual C#, Visual Studio, Win32, and Windows Media are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A and/or other countries

The names of actual companies and products mentioned herein may be the trademarks of their respective owners

Trang 3

Instructor Notes Module 9: Implementing a Nonstandard Web Service

This module covers two examples of Web Services that are not simple alone network accessible application programming interfaces (APIs)

stand-After completing this module, students will be able to:

! Explain how to implement a HTML screen scraping Web Service

! Identify the scenarios where aggregated Web Services are appropriate

! Implement an aggregating Web Service that uses multiple Web Services

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 Microsoft® PowerPoint® file 2524A_09.ppt

Preparation Tasks

To prepare for this module:

! Read all of the materials for this module

! Practice all of the demonstrations

! Complete the lab

Demonstration

This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes

Example of an Aggregated Web Service

! To demonstrate the NorthwindClient application

1 Start the application NorthwindClient.exe, which can be found in the folder

<install folder>\Labfiles\Lab09\Solution\NorthwindClient\bin\Debug

2 In the From list, click Woodgrove Online Bank

3 In the To list, click Contoso Micropayments

4 Click Transfer

5 Explain that $100 has been transferred from an account at the Woodgrove bank to an account at the micropayment service, named Contoso

6 Explain that the Northwind Traders Web Service took care of all the details

of managing the transfer, including retrieving routing numbers, etc

Presentation:

45 Minutes

Lab:

90 Minutes

Trang 4

! To explain the Northwind Traders Web Service implementation

1 In Microsoft Visual Studio NET, open the <install folder>\WebServicesSolution\Northwind\Northwind project

2 Open Traders.asmx.cs

3 Explain the implementation of GetTModelEndPoints, GetTransferSinks and GetTransferSources methods

4 Explain the EFTTransfer method

a Describe how the Northwind Traders Web Service interacts with the Contoso and Woodgrove Web Services

b Explain how the binding information is used

! To explain the implementation of the CreditAccount method in the Contoso Web Service

1 Open the <install folder>\WebServicesSolution\Contoso\Contoso project

2 Open Micropayment.asmx.cs

3 Explain the implementation of CreditAccount method

a Explain routing information (It is information required by a financial institution for electronically transferring funds to an account at another financial institution.)

b Explain that the Contoso Web Service is a consumer of the Woodgrove Web Service

! To explain the implementation of the AuthorizeFundsTransfer method

in the Woodgrove Web Service

1 Open the <install folder>\WebServicesSolution\Woodgrove\Woodgrove

project

2 Open Bank.asmx.cs

3 Explain the implementation of AuthorizeFundsTransfer method

Explain the information that is contained in the EFTBindingInfo class

! To show that money is transferred between the accounts

1 Run <install folder>\Labfiles\Lab07\Solution\Woodgrove and Contoso

Account Manager\bin\Debug\WebServiceClient.exe

Leave the default accounts selected and note the account balance

2 Switch to the NorthwindClient.exe application

3 Transfer funds from the Woodgrove Online Bank to the Contoso Micropayment Service

4 Switch to the WebServiceClient.exe application

5 Click Update Account Info

6 Point out that the balance has been reduced by $100

Trang 5

Module Strategy

Use the following strategy to present this module:

! HTML Screen Scraping Web Services For many students the concept of a virtual Web Service will not be intuitive Explain that this section is important because it is unlikely that owners of most of the data on the Internet will ever provide access to their data through Web Services However, making this data accessible to clients through a Web Service is a useful paradigm Because consumers interact with a Web Service through a proxy class, if the proxy class simply retrieves the raw data and the parses the data locally, the consumer need not

be aware that the processing takes place on the client and not on the server

A detail that you should emphasize is that screen scraping Web Service proxies can only communicate using the HTTP-GET protocol

! Aggregating Web Services Explain that Web Services can be viewed as sets of functionality There is

no reason why these sets of functionality should not be aggregated to provide richer functionality The module discusses a number of models for aggregating Web Services Each model should be analyzed and its areas of application should be discussed You must teach this section by basing it on the final lab scenario

Trang 7

Overview

! HTML Screen Scraping Web Services

! Aggregating Web Services

***************************** ILLEGAL FOR NON - TRAINER USE ******************************

In some scenarios, it may be unnecessary to actually implement a standard Web Service In other scenarios your Web Service might to reuse the functionality of other Web Services as part of its implementation, and thereby assume the role

of a Web Service consumer This module shows you how to implement Web Service based solutions for such special scenarios

After completing this module, you will be able to:

! Explain how to implement a HTML screen scraping Web Service

! Identify the scenarios where aggregated Web Services are appropriate

! Implement an aggregating Web Service that uses multiple Web Services

Trang 8

" HTML Screen Scraping Web Services

! Regular Expressions in the NET Framework

! Using Regular Expressions in WSDL Documents

! Demonstration: Screen Scraping an HTML Document

***************************** ILLEGAL FOR NON - TRAINER USE ******************************

Most data on the Web today is available only as unstructured HTML documents Many of the Web pages contain valuable information, but retrieving information from these pages requires that you parse HTML documents to extract data

Writing code to parse data is a tedious and error prone process, if the data is not organized in well-defined fields A useful way to reduce the effort involved is

to use an engine that can support regular expressions, which can be used to parse data

Microsoft® has extended the standard Web Service Description Language (WSDL) grammar to allow the use of regular expressions to specify the information in a document that is to be extracted The Web Services defined by these WSDL documents do not actually exist Instead, after you create the WSDL file, you can generate a Web Service proxy using that file The client that uses this proxy class can now retrieve information from a Web page as if the page is a real Web Service In such cases, there is no code to be written or maintained on the Web Server From the perspective of the Web Server, only Web pages are served to clients When you extract information from an HTML

document using this technique, it is known as HTML screen scraping

screen scraping Web

Services that extract

information from HTML

documents

Delivery Tip

The information in the

student notes is more than

introductory material

Therefore, ensure that you

cover this material

Trang 9

Regular Expressions in the NET Framework

! The Regex Class

! The Match Class

! The MatchCollection Class

***************************** ILLEGAL FOR NON - TRAINER USE ******************************

Regular expressions provide a powerful, flexible, and efficient method for processing text The extensive pattern-matching notation of regular expressions allows you to quickly parse large amounts of text to find specific character patterns; to extract, edit, replace, or delete text substrings; or to add the extracted strings to a collection in order to generate a report Regular expressions are an indispensable tool for many applications that manipulate strings, such as HTML processing, log file parsing, and HTTP header parsing Microsoft NET Framework regular expressions are designed to be compatible with Perl 5.0 regular expressions The NET Framework regular expression

classes are found in the System.Text.RegularExpressions namespace

The Regex Class

The Regex class represents a read-only regular expression The following example creates an instance of the Regex class and defines a simple regular

expression when the object is initialized

Regex r;

r = new Regex(@"\s2000");

In the preceding code, the @ prefix is added to the string to prevent the \

(backslash) character from being treated as an escape character

Regular expressions provide

a powerful, flexible, and

efficient method for

processing text

Delivery Tip

Emphasize that screen

scraping technology is not

restricted in its use to Web

pages

Trang 10

The Match Class

The Match class represents the first match when a regular expression is applied

to an input string In the following example, the instance of the Match class is returned by the Match method of the Regex class The Match method finds the first match in the input string The example uses the Success property of the Match class to find out if a match was found

Regex r = new Regex("abc");

Match m = r.Match("123abc456");

if (m.Success) {

Console.WriteLine("Found match at position " + m.Index); }

Escaped characters

Most of the important regular expression language operators are unescaped

single characters The escape character \ (a single backslash) notifies the regular

expression parser that the character following the backslash is not an operator For example, an unescaped * (asterisk) is a repeating quantifier, but an escaped

* is treated as the literal character * The following table lists the character escapes that are recognized in regular expressions

+, ?, and \ match themselves

character classes; otherwise, in a regular expression, \b denotes a word boundary (between \w and \W characters)

to three digits) For example, \040 represents a space

hexadecimal representation (exactly two digits)

Trang 11

(continued)

example, \cC is CTRL+C

hexadecimal representation (exactly four digits)

character that is not recognized as an escaped character, the \ matches that character For example, \* is the same as

\x2A

Character classes

Character classes are the set of characters that define the substring to match The following table summarizes character matching syntax

Singleline option is specified

specified set of characters

the specified set of characters

For more information, see the topic Regular Expression Language Elements

in the NET Framework SDK documentation

Trang 12

The MatchCollection Class

The MatchCollection class represents a sequence of successful

non-overlapping matches when a regular expression is applied to an input string

Instances of MatchCollection are returned by the Regex.Matches property The following example uses the Matches method of the Regex class to fill an instance of the MatchCollection class with all the matches found in the input

string The following example code copies the match collection to a string array that holds all of the matches, and an integer array that indicates the position of each match in the input string:

MatchCollection mc;

string[] results = new String[20];

int[] matchposition = new int[20];

Regex r = new Regex("abc");

Trang 13

Using Regular Expressions in WSDL Documents

! Create a WSDL Document Manually

! Specify the Output Message Format in the output Element Within the binding Element

***************************** ILLEGAL FOR NON - TRAINER USE ******************************

If you want to consume a HTML file or any flat file as if it were a Web Service

by creating a Web Service proxy, you need a service description In cases where you apply screen scraping to flat files, a WSDL document cannot be

automatically generated for creating the proxy Therefore, you have to manually construct the WSDL document

The part that is of interest to us in a manually created WSDL document is the format of the output messages that will be generated by the proxy The output

message format is specified in the output element within the binding element

The output is simply an XML document with the following structure:

perform further pattern matching within a match

The following is an example of a regular expression code in a WSDL document:

To explain how regular

expressions can be used in

WSDL documents

Lead-in

If you want to consume a

flat file as if it were a Web

Service by creating a Web

Service proxy, you need a

service description

Example

Trang 14

Demonstration: Screen Scraping an HTML Document

***************************** ILLEGAL FOR NON - TRAINER USE ******************************

In this demonstration, you will see how to screen scrape an HTML document using WSDL and Web Service proxies

Consider the following HTML document:

In this demonstration, you

will see how to screen

scrape an HTML document

using WSDL and Web

Service proxies

Delivery Tip

Show the example XML

document to students using

the file <install

folder>\Democode\Mod09\

sales.html

Trang 15

1 <html>

4 <h1>Northwind Traders Financial Report</h1>

5 <table border="1" cellpadding="5">

Trang 16

To mimic a Web Service that can provide a list of sales information by region, you can have the following WSDL document:

23 <urt:match name="Sales" type="RegionSales"

pattern="&lt;tr.*?&gt;(.*?)&lt;/tr.*?&gt;" repeats="*">

Explain the WSDL code

sample using the file

<install

folder>\Democode\Mod09\

sales.wsdl

Trang 17

After processing the preceding service description to generate a proxy, the following proxy class is produced:

The preceding proxy class can be used as follows:

Explain the C# proxy code

sample using the file

<install

folder>\Democode\Mod09\

sales.cs

Ngày đăng: 17/01/2014, 08:20

Nguồn tham khảo

Tài liệu tham khảo Loại Chi tiết
3. Add a private method with the following signature: private AccessPoint[] GetTModelEndPoints(string tModelKey) Khác
4. Within this method, create an ArrayList object Khác
5. Within a try block, set the Url property of the Inquire object to http://localhost/uddi/inquire.asmx Khác
7. Add a tModelKey to the FindBusiness.TModelKeys collection by using the tModelKey parameter Khác
8. Call the Send method of the FindBusiness object Khác
9. Store the returned BusinessList object Khác

TỪ KHÓA LIÊN QUAN