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

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

Đ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

Contents Overview 1 HTML Screen Scraping Web Services 2 Aggregating Web Services 13 Lab 9: Implementing an Aggregated Web Service 17 Review 28 Module 9: Implementing a Nonstandard Web Service 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. Module 9: Implementing a Nonstandard Web Service iii Instructor Notes Module 9: Implementing a Nonstandard Web Service This module covers two examples of Web Services that are not simple stand- alone network accessible application programming interfaces (APIs). 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 iv Module 9: Implementing a Nonstandard Web Service ! 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. Module 9: Implementing a Nonstandard Web Service v 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. Module 9: Implementing a Nonstandard Web Service 1 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. Topic Objective To provide an overview of the module topics and objectives. Lead-in In this module, you will learn about implementing nonstandard Web Services such as HTML screen scraping and aggregating Web Services. 2 Module 9: Implementing a Nonstandard Web Service " "" " 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. Topic Objective To introduce the topics in this section. Lead-in In this section, you will look at how to build HTML 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. Module 9: Implementing a Nonstandard Web Service 3 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. Topic Objective To introduce the regular expressions supported in the .NET Framework. Lead-in 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. 4 Module 9: Implementing a Nonstandard Web Service 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. Escaped character Meaning ordinary characters Characters other than ., $, ^, {, [, (, |, ), *, +, ?, and \ match themselves. \a Matches a bell alarm (\u0007). \b Matches backspace (\u0008) if in [ ] character classes; otherwise, in a regular expression, \b denotes a word boundary (between \w and \W characters). \t Matches a tab (\u0009). \r Matches a carriage return (\u000D). \v Matches a vertical tab (\u000B). \f Matches a form feed (\u000C). \n Matches a new line (\u000A). \e Matches an escape (\u001B). \040 Matches an ASCII character as octal (up to three digits). For example, \040 represents a space. \x20 Matches an ASCII character using hexadecimal representation (exactly two digits). [...]... of characters [0- 9a- fA-F] Matches any character in the specified ranges \w Matches any word character Same as [azA-Z_0-9] \W Matches any nonword character Same as [ ^a- zA-Z_0-9] \s Matches any white-space character Same as [\f\n\r\t\v] \S Matches any non-white-space character Same as [^\f\n\r\t\v] \d Decimal digit Same as [0-9] \D Nondigit Same as [^0-9] For more information, see the topic Regular Expression... "_CreateTransaction" 20 Module 9: Implementing a Nonstandard Web Service 3 For each of the parameters of the _CreateTransaction stored procedure, add a SqlParameter object to the SqlCommand object _CreateTransaction(@userID AS nvarchar(16), @password AS nvarchar(16), @transDate AS datetime, @amount AS money, @desc AS nvarchar(50), @type AS char(2), @transactionID AS int OUTPUT) Most of the parameters for.. .Module 9: Implementing a Nonstandard Web Service 5 (continued) Escaped character Meaning \cC Matches an ASCII control character; for example, \cC is CTRL+C \u0020 Matches a Unicode character by using a hexadecimal representation (exactly four digits) \ When \ (backslash) is followed by a character that is not recognized as an escaped character, the \ matches that character For example, \* is the same... and values that are specific to each parameter: Name Type Size Value @userID NVarChar 16 authInfo.Username @password NVarChar 16 authInfo.Password @transdate DateTime 8 DateTime.Now @amount Money 8 the CreditAccount amount parameter @desc NVarChar 50 a string that contains the transactionID member of the EFTConfirmation object @type Char 2 “CR” @transactionID Int 4 null For the @transactionID parameter,... demonstration, you will look at an example of an aggregated Web Service, which acts as a portal to other Web Services You will implement this aggregated Web Service in the lab for this module Module 9: Implementing a Nonstandard Web Service 17 Lab 9: Implementing an Aggregated Web Service Topic Objective To introduce the lab Lead-in Contoso Micropayment Web Service UDDI Registry Woodgrove Bank Web Service... is the same as \x 2A Character classes Character classes are the set of characters that define the substring to match The following table summarizes character matching syntax Character class Meaning Matches any character except \n unless the Singleline option is specified [aeiou] Matches a single character included in the specified set of characters [^aeiou] Matches any single character that is not in... provide additional value to consumers Instead of a consumer having to interact with multiple Web Services, you can have an aggregating Web Service that acts as a portal to other Web Services Consider the following scenario A Web Service named Northwind Traders Web Service acts a portal, using which you can transfer funds electronically between financial institutions that provide Web Services to transfer... firewall by authenticating all requests, and then forwarding them to the unsecured Web Service There are many other scenarios where one Web Service can act as a gateway to other Web Services For example, a Web Service might forward requests to various Web Services based on metrics like response time, geographic location, user role, etc Module 9: Implementing a Nonstandard Web Service 15 Simple Interfaces... SqlParamter class can be assigned default values The following table specifies the parameters and the default values it should use: Parameter name Value ParameterDirection System.Data.ParameterDirection.Input IsNullable True Precision ((System.Byte)( 0)) Scale ((System.Byte)( 0)), SourceColumn “” DataRowVersion System.Data.DataRowVersion.Current The following table lists the parameters to be added and... (method) that accepted the names of a city, state, or province, and country as arguments; and returned the image of the appropriate tile This Web Service can retrieve the latitude and longitude from a Web Service that provides this information, and then uses this information to find the tile ID and the image using the TerraServer Web Service Portals to Web Services A Web Service can aggregate other Web Services . Scraping Web Services 2 Aggregating Web Services 13 Lab 9: Implementing an Aggregated Web Service 17 Review 28 Module 9: Implementing a Nonstandard. scenarios where aggregated Web Services are appropriate. ! Implement an aggregating Web Service that uses multiple Web Services. Materials and Preparation

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

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan