Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 48 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
48
Dung lượng
859,87 KB
Nội dung
Module 11: Internet Access Contents Overview Internet Application Scenarios The WebRequest and WebResponse Model Application Protocols 16 Handling Errors 25 Security 28 Best Practices 35 Lab 11: Creating a DateTime Client/Server Application 36 Review 41 Course Evaluation 43 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, place or event 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-2002 Microsoft Corporation All rights reserved Microsoft, ActiveX, BizTalk, IntelliMirror, Jscript, MSDN, MS-DOS, MSN, PowerPoint, Visual Basic, Visual C++, Visual C#, Visual Studio, Win32, Windows, Windows Media, and Window NT 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 11: Internet Access iii Instructor Notes Presentation: 60 Minutes After completing this module, students will be able to: ! Lab: 45 Minutes Use the basic request/response model to send and receive data over the Internet ! Use the System.Net classes to communicate with other applications by using the HTTP, Transmission Control Protocol (TCP), User Datagram Protocol (UDP), and Socket Internet protocols 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 Microsoft® PowerPoint® file 2349B_11.ppt Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module ! Complete the lab iv Module 11: Internet Access Module Strategy Use the following strategy to present this module: ! Internet Application Scenarios Briefly introduce examples of Internet applications that use the System.Net classes, including server-side ASP.NET applications, peer-to-peer Microsoft Windows® Forms applications that act as servers and clients to send and receive data, and client applications that periodically access the network for updates ! The WebRequest and WebResponse Model Introduce the WebRequest and WebResponse model Explain how the Microsoft NET Framework uses the Uniform Resource Identifier (URI) to identify the desired communication protocol and Internet resource Discuss network streams as the means of obtaining and receiving Web data Explain how to use the WebRequest class to request data from a server, invoke the request for the Internet resource, and send data through a network stream Discuss how the WebResponse.GetResponseStream method serves as the means of obtaining a stream that contains response data from a network resource ! Application Protocols Discuss the HTTP, TCP, and UDP protocol support that is provided in the NET Framework, as well as information about using the Windows Sockets interface to implement custom protocols ! Handling Errors Discuss how the WebRequest and WebResponse classes can throw system exceptions, such as InvalidArgumentException, and Web-specific exceptions, which are instances of WebException and thrown by the GetResponse method ! Security Explain how an application can provide security for sending and receiving data over the Internet by using a Web proxy, Secure Sockets Layer (SSL) encryption, Internet authentication, and the NET Framework code access permissions ! Best Practices Briefly outline the list of recommendations that will help students use the classes that are contained in System.Net more effectively Module 11: Internet Access Overview Topic Objective To provide an overview of the module topics and objectives ! ! Application Protocols ! Handling Errors ! Security ! In this module, you will learn about the basic request/response model that is used to send and receive data over the Internet, the System.Net classes that are used to communicate with other applications, and various techniques to enhance application security and performance The WebRequest and WebResponse Model ! Lead-in Internet Application Scenarios Best Practices *****************************ILLEGAL FOR NON-TRAINER USE****************************** The Microsoft® NET Framework System.Net and System.Net.Sockets namespaces provide a layered, extensible, and managed implementation of Internet protocols that applications can use to send or receive data over the Internet The System.Net classes provide functionality that is similar to the Microsoft WinInet API These classes provide varying levels of detail, from a generic request/response model to control over application protocols and sockets In particular, the System.Net classes are designed for writing scaleable, high-performance applications An application can use the System.Net classes to communicate with any other application that supports the basic Internet protocols However, that other application need not be a NET application The NET Framework provides alternative mechanisms for inter-application communication For example, NET Framework remoting implements a generic mechanism for NET Framework objects to interact with one another across application domains In addition, the System.Web.Services namespace contains classes for applications to build and use XML Web services that are based on the standard Simple Object Access Protocol (SOAP) For more information about the remoting and XML Web services approaches to inter-application communication, see Module 12, “Serialization,” in Course 2349B, Programming with the Microsoft NET Framework (Microsoft Visual C#™ NET) After completing this module, you will be able to: ! Use the basic request/response model to send and receive data over the Internet ! Use the System.Net classes to communicate with other applications by using the Hypertext Transfer Protocol (HTTP), Transmission Control Protocol (TCP), User Datagram Protocol (UDP), and Socket Internet protocols Module 11: Internet Access Internet Application Scenarios Topic Objective To introduce Internet application scenarios that use the System.Net classes ! Lead-in ! Server-Side ASP.NET Applications " Several types of applications use the System.Net classes to send or receive data over the Internet Peer-to-Peer Applications " ! Obtain data from back-end sources for a browser request Send and receive data by acting as servers and clients Client Applications That Periodically Access the Network " A robust implementation of HTTP 1.1, including: Pipelining, chunking, authentication, pre-authentication, encryption, proxy support, server certificate validation, and connection management *****************************ILLEGAL FOR NON-TRAINER USE****************************** Several types of applications use the System.Net classes to send or receive data over the Internet The following three Internet application scenarios are examples of Internet applications that use the System.Net classes: ! Server-side ASP.NET applications that request data from server resources in response to a browser request The System.Net classes are designed for writing scalable, high-performance ASP.NET middle-tier applications The server-side ASP.NET scenario requires a robust middle-tier networking stack that can tolerate a high load The System.Net classes specifically fulfill this important customer requirement Such features as connection management, pipelining, Keep-alive, and asynchronous operations ensure strong support for the middle tier In addition, because the System.Net classes are part of an overall framework, integration with ASP.NET features, such as impersonation and caching, is seamless ! Peer-to-peer Windows Forms applications that act as servers and clients to send and receive data ! Client applications that periodically access the network for updates The System.Net classes expose a robust implementation of the HTTP protocol Because a large share of Internet traffic travels over the HTTP protocol, the protocol’s importance as an application protocol is significant The System.Net classes support most of the HTTP 1.1 protocol features The advanced features of HTTP 1.1 include pipelining, chunking, authentication, pre-authentication, encryption, proxy support, server certificate validation, connection management, and HTTP extensions Module 11: Internet Access # The WebRequest and WebResponse Model Topic Objective To introduce the topics in the section Uniform Resource Identifier ! NetworkStream Class ! Creating a WebRequest ! Invoking a WebRequest ! Sending Data Receiving Data ! Internet applications can be classed broadly into two types: client applications that request information, and server applications that respond to information requests from clients ! ! Lead-in Using the WebRequest and WebResponse Model *****************************ILLEGAL FOR NON-TRAINER USE****************************** Internet applications can be classed broadly into two types: client applications that request information, and server applications that respond to information requests from clients The classic Internet client/server application is the World Wide Web, where people use browsers to access documents and other data that is stored on Web servers worldwide Applications are not limited to playing either the client or server role; the familiar middle-tier application server responds to requests from clients by requesting data from another server In this case, it is acting as both a server and a client The client application makes a request by identifying the desired Internet resource and the communication protocol that will be used to exchange the request and response If necessary, the client application also specifies any additional data that is required to complete the request, such as proxy location or authentication information Authentication information includes such information as user name and password When the request is formed, it can be sent to the server After the server has received the request and processed the response, the response is returned to the client application The response includes information that supplements the contents of the response, such as the type of content, which may include raw text or XML data Module 11: Internet Access The NET Framework provides classes that can be used to implement a request/response model to access Internet resources The two principal classes are the WebRequest class, which contains a request for the resource; and the WebResponse class, which provides a container for the incoming response In addition, the Uri class is used to contain a Uniform Resource Identifier (URI), which identifies the Internet resource that you are seeking The NetworkStream class is used to write and read the data Note A Uniform Resource Identifier URI is a compact representation of a resource that is available to your application through the Internet You may be more familiar with the term, URL, which stands for Uniform Resource Locator URLs form a subset of the more general URI naming scheme A URL identifies an Internet resource that has a Web page address For applications that need to make simple requests for Internet resources, the WebClient class provides common methods for uploading data to or downloading data from an Internet server WebClient relies on the WebRequest class to provide access to Internet resources; therefore, the WebClient class can use any registered pluggable protocol Module 11: Internet Access Uniform Resource Identifier Topic Objective To introduce the four parts of the URI ! URI Contains: " Path identifier – specifies location on the server " ! Server identifier – specifies DNS name or TCP address " The NET Framework uses the URI to identify the desired communication protocol and Internet resource Scheme identifier – specifies protocol to be used " Lead-in Optional query string – provides additional request information Example: http://www.contoso.com/whatsnew.aspx?date=today " Scheme identifier – http " Server identifier – www.contoso.com " Path identifier – /whatsnew.aspx " Query String – ?date=today *****************************ILLEGAL FOR NON-TRAINER USE****************************** The NET Framework uses the URI to identify the desired communication protocol and Internet resource The URI consists of at least three, and possibly four, parts: ! The scheme identifier, which identifies the communications protocol that is used by the request and response ! The server identifier, which consists of a Domain Name System (DNS) host name or TCP address that uniquely identifies the server on the Internet ! The path identifier, which locates the requested information on the server ! An optional query string, which passes information from the client to the server For example, the URI http://www.contoso.com/whatsnew.aspx?date=today consists of the scheme identifier http, the server identifier www.contoso.com, the path identifier /whatsnew.aspx, and the query string ?date=today Module 11: Internet Access NetworkStream Class Topic Objective ! To explain the function of Network streams in the NET Framework A NetworkStream Object Provides: " " When resources on the Internet are obtained by using the System.Net classes, the data that is being sent and received is represented through a Stream object ! Methods That Are Compatible with Other NET Streams " Lead-in A Way to Send and Receive All Types of Web Data Processing of Data As It Arrives System.Text.Encoding – Characters from and to Bytes // reading ASCII stream to string // reading ASCII stream to string Byte[] read = new Byte[32]; Byte[] read = new Byte[32]; int bytes = anASCIIStream1.Read(read, 0, read.Length); int bytes = anASCIIStream1.Read(read, 0, read.Length); string stringData = Encoding.ASCII.GetString(read); string stringData = Encoding.ASCII.GetString(read); // writing string to ASCII stream // writing string to ASCII stream Byte[] asciiBytes = Encoding.ASCII.GetBytes(stringData); Byte[] asciiBytes = Encoding.ASCII.GetBytes(stringData); anASCIIStream2.Write(asciiBytes, 0, asciiBytes.Length); anASCIIStream2.Write(asciiBytes, 0, asciiBytes.Length); ! Sequential Blocks Use StreamReader and StreamWriter *****************************ILLEGAL FOR NON-TRAINER USE****************************** When resources on the Internet are obtained by using the System.Net classes, a Stream object represents the data that is being sent and received Streams provide: ! A common way to send and receive Web data Whether the actual contents of the file are HTML, XML, or another format, an application uses Stream.Write and Stream.Read to send and receive byte data ! Compatibility with streams across the NET Framework Streams are used throughout the NET Framework, which provides a rich infrastructure for handling them For example, by changing only the few lines of code that initialize the stream, you can modify an application that reads XML data from a file stream to read data from a network stream instead The major differences between the NetworkStream class and other streams are that the NetworkStream class is not seekable, the CanSeek property always returns false, and the Seek and Position methods throw a NotSupportedException ! Processing of data as it arrives Streams provide access to data as it arrives from the Internet, rather than forcing your application to wait for an entire data set to be downloaded 30 Module 11: Internet Access Secure Sockets Layer Topic Objective To explain how SSL is used for secure network communication ! SSL Is Used Automatically If the URI Begins with https Lead-in The WebRequest and WebResponse classes use SSL automatically String MyURI = "https://www.contoso.com/"; String MyURI = "https://www.contoso.com/"; WebRequest wReq = WebRequest.Create(MyURI); WebRequest wReq = WebRequest.Create(MyURI); *****************************ILLEGAL FOR NON-TRAINER USE****************************** The WebRequest and WebResponse classes use SSL automatically The WebRequest object decides to use SSL on the basis of the URI that it is assigned If the URI begins with https:, SSL is used If the URI begins with http:, SSL is not used The following example illustrates the use of SSL: String MyURI = "https://www.contoso.com/"; WebRequest wReq = WebRequest.Create(MyURI); Module 11: Internet Access 31 Internet Authentication Topic Objective To introduce the client authentication mechanisms that are supported by the System.Net classes ! " ! Basic, digest, negotiate, NTLM, and Kerberos authentication " Lead-in The System.Net classes support a variety of client authentication mechanisms, including the standard Internet authentication methods: basic, digest, negotiate, NTLM, and Kerberos authentication, and custom methods that you can create .NET Supports Various Kinds of Authentication Users can also create their own authentication Credentials Stored in Classes " NetworkCredential – for a single Internet resource " CredentialCache – for multiple Internet resources ! Authentication Managed by the AuthenticationManager ! Some Schemes Allow Pre-Authentication to Save Time *****************************ILLEGAL FOR NON-TRAINER USE****************************** The System.Net classes support a variety of client authentication mechanisms, including the standard Internet authentication methods: basic, digest, negotiate, NTLM, and Kerberos authentication, and custom methods that you can create Classes and Interfaces Used for Authentication Authentication credentials are stored in the NetworkCredential and CredentialCache classes, which implement the ICredentialLookup interface When one of these classes is queried for credentials, it returns an instance of the NetworkCredential class The AuthenticationManager class manages the authentication process, while an authentication module class that implements the IAuthenticationModule interface performs the actual authentication process You must register a custom authentication module with the AuthenticationManager before it can be used Modules for the basic, digest, negotiate, NTLM, and Kerberos authentication methods are registered by default The NetworkCredential Class The NetworkCredential class stores a set of credentials, which is associated with a single Internet resource and that is identified by a URI, and returns them in response to any call to the GetCredential method The NetworkCredential class is typically used by applications that access a limited number of Internet resources or by applications that use the same set of credentials in all cases The CredentialCache Class The CredentialCache class stores a collection of credentials for various Internet resources When the GetCredential method is called, CredentialCache returns the proper set of credentials, as determined by the URI of the Internet resource and the requested authentication scheme Because the CredentialCache class stores all of the credentials and provides them as requested, applications that use a variety of Internet resources with different authentication schemes benefit from using the CredentialCache class 32 Module 11: Internet Access The Authentication Process When an Internet resource requests authentication, the WebRequest.GetResponse method sends the WebRequest and the request for credentials to the AuthenticationManager The request is then authenticated according to the following procedure: The AuthenticationManager calls the Authenticate method on each of the registered authentication modules in the order that they were registered The AuthenticationManager uses the first module that does not return null to carry out the authentication process The details of the process vary depending on the type of authentication module involved When the authentication process is complete, the authentication module returns an Authorization instance to the WebRequest that contains the information that is needed to access the Internet resource Some authentication schemes can authenticate a user without first making a request for a resource An application can save time by pre-authenticating the user with the resource, thus eliminating at least one roundtrip to the server Alternatively, the application can perform authentication during program startup to be more responsive to the user later Authentication schemes that can use pre-authentication set the CanPreAuthenticate property to true Basic and Digest Authentication The System.Net implementation of basic and digest authentication complies with RFC2617, “HTTP Authentication: Basic and Digest Authentication,” which is available on the World Wide Web Consortium (W3C) Web site at http://www.w3c.org To use basic and digest authentication, an application must provide a user name and password in the Credentials property of the WebRequest object that it uses to request data from the Internet, as shown in the following example: Caution String literals in an application are stored and transported as clear text Therefore, you should avoid putting sensitive information such as passwords in string literals // variables named username and password // of type string have been previously assigned String MyURI = "http://www.contoso.com/"; WebRequest wReq = WebRequest.Create(MyURI); wReq.Credentials = new NetworkCredential( username, password); Module 11: Internet Access 33 NTLM and Kerberos Authentication Default NTLM authentication and Kerberos authentication use the Microsoft Windows NT® user credentials that are associated with the calling application to attempt authentication with the server to pass the username, password, and domain to the host, as in the following example: // variables named username, password, and domain // of type string have been previously assigned String MyURI = "http://www.contoso.com/"; WebRequest wReq = WebRequest.Create(MyURI); wReq.Credentials = new NetworkCredential(username, password, domain); Applications that need to connect to Internet services by using the credentials of the application user can so with the user’s default credentials, as in the following example: String MyURI = "http://www.contoso.com/"; WebRequest wReq = WebRequest.Create(MyURI); wReq.Credentials = CredentialCache.DefaultCredentials; The negotiate authentication module determines whether the remote server is using NTLM or Kerberos authentication and sends the appropriate response Note NTLM authentication does not work through a proxy server Passport Authentication Passport authentication is a centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites This benefits the user because it is no longer necessary to log on to access new protected resources or sites If you want your site to be compatible with Passport authentication and authorization, this is the provider you should use For more information, see the Passport documentation located at http://www.passport.com/business 34 Module 11: Internet Access Permissions Topic Objective To explain which permission classes best suit which application types Lead-in The WebPermissions and SocketPermissions classes provide Internet security for applications that use System.Net ! WebPermissions " ! SocketPermissions " ! Controls an application's right to request data from a URI or to serve a URI to the Internet Controls an application's right to accept data on a local port or to contact applications Choose Permission Class Based on Application Use " " ! WebRequest and its descendents use WebPermissions Socket-level access uses SocketPermissions Both Classes Support Two Kinds of Permissions " Accept – application can answer an incoming connection " Connect – application can initiate a connection *****************************ILLEGAL FOR NON-TRAINER USE****************************** The WebPermissions and SocketPermissions classes provide Internet security for applications that use System.Net The WebPermissions class controls an application’s right to request data from a URI or to serve a URI to the Internet The SocketPermissions class controls an application’s right to accept data on a local port or to contact applications through a transport protocol at another address that is based on the host, port number, and transport protocol You should choose the permission class on the basis of your application type Applications that use WebRequest and its descendents should use the WebPermissions class to manage permissions Applications that use socket-level access should use the SocketPermissions class to manage permissions WebPermissions and SocketPermissions define two permissions: accept and connect Accept grants the application the right to answer an incoming connection from another party Connect grants the application the right to initiate a connection to another party For WebPermissions, accept means that an application can export a particular URI anywhere on the Internet Connect means that an application can access that URI, whether it is remote or local For SocketPermissions, accept means that an application can accept incoming connections on a local transport address Connect means that an application can connect to a remote, or potentially local, transport address Module 11: Internet Access 35 Best Practices Topic Objective To introduce best practices that will help students use the System.Net classes more effectively ! ! The following recommendations will help you use the classes that are contained in System.Net more effectively For Better Performance, Use Asynchronous Methods ! Lead-in When Possible, Use WebRequest and WebResponse, Instead of Protocol-Specific Subclasses Tune Performance by Adjusting the Number of Connections " ConnectionLimit property in the ServicePoint instance ! When Possible, Use TcpClient or UdpClient, Instead of Writing Directly to a Socket ! Use the CredentialCache Class If Credentials Are Required *****************************ILLEGAL FOR NON-TRAINER USE****************************** The following recommendations will help you use the classes that are contained in System.Net more effectively: ! Whenever possible, use WebRequest and WebResponse, instead of typecasting to descendent classes Applications that use WebRequest and WebResponse can take advantage of new Internet protocols without extensive code changes ! When writing ASP.NET applications that run on a server that uses the System.Net classes, it is often better, from a performance standpoint, to use the asynchronous methods for GetResponse and GetResponseStream ! Set the ConnectionLimit property in the ServicePoint instance for your application The number of connections opened to an Internet resource can have a significant effect on network performance and throughput By default, System.Net uses two connections per application for each host Setting the ConnectionLimit property in the ServicePoint instance for your application can increase this number ! When writing socket-level protocols, try to use the TcpClient or UdpClient classes, instead of writing directly to a socket The TcpClient and UdpClient classes encapsulate the creation of TCP and UDP sockets without requiring you to handle the details of the connection ! When accessing sites that require credentials, use the CredentialCache class to create a cache of credentials, rather than supplying them with every request The CredentialCache class will search the cache to find the appropriate credential to present with a request, thus relieving you of the responsibility of creating and presenting credentials based on the URI 36 Module 11: Internet Access Lab 11: Creating a DateTime Client/Server Application Topic Objective To introduce the lab Lead-in In this lab, you will create a client application that uses the System.Net.Sockets TcpClient class to connect to and obtain date and time information from a server You will also create a server application that uses the System.Net.Sockets TcpListener class to accept requests from and provide date and time information to clients *****************************ILLEGAL FOR NON-TRAINER USE****************************** Objectives After completing this lab, you will be able to: ! Create a client application that uses the System.Net.Sockets.TcpClient class to connect to and obtain date and time information from a server ! Create a server application that uses the System.Net.Sockets.TcpListener class to accept requests from and provide date and time information to clients Lab Setup Only solution files are associated with this lab The solution files for this lab are in the folder \Labs\Lab11\Solution Scenario In this lab, you will create two Microsoft Visual Studio® NET console applications: DateTimeClient and DateTimeServer The DateTimeClient application will make a TCP connection to the DateTimeServer application and obtain a stream that contains date and time information The DateTimeClient will read the stream and convert the stream’s ASCII data into a string that is then output to the console Estimated time to complete this lab: 45 minutes Module 11: Internet Access 37 Exercise Creating the DateTime Server In this exercise, you will create a server application that will provide date and time information to clients through TCP ! Create the server application In Visual Studio NET, create a new C# console application project named DateTimeServer in \Labs\Lab11 Rename the starting C# source file Datetimeserver.cs Add the following using statements: using System.Net; using System.Net.Sockets; using System.Text; Rename the wizard generated Class1 to Server Modify the Main method in the following steps In the try section of a try/catch block: a Instantiate a TcpListener object to listen on port 14 b Start the TcpListener object c Write out the following message to the console: Waiting for clients to connect Press Ctrl+c to Quit d Enter an infinite loop that will: i Accept TCP client connections using the AcceptSocket method ii Call a DateTime method to get the current date and time iii Create a string that consists of the short version of the date, followed by the long version of the time iv Convert the string to an ASCII-encoded byte array v Send this byte array to the TCP client vi Close the socket vii Write out to the console a message that contains the string that was just sent In the catch section of the try/catch block: • Catch any exceptions of type SocketException and if the exception’s ErrorCode property has a value of 10048, then write to the console a message that states “Connection to this port failed There is another server is listening on this port.” Build the server application 38 Module 11: Internet Access Exercise Creating the DateTime Client In this exercise, you will create a client application The client application takes as its runtime argument the name of the computer on which the server is running The client connects to the server to obtain date and time information through TCP The client then displays the date and time information on the console ! Create the client application In Visual Studio NET, create a new C# console application project named DateTimeClient in \Labs\Lab11 Rename the starting C# source file Datetimeclient.cs Add the following using statements: using using using using System.Net; System.Net.Sockets; System.IO; System.Text; Rename the wizard generated Class1 to Client Make the static Main method capable of handling runtime-supplied arguments In the Main method, add code to: a Create a TcpClient object b Create a byte array object of size 32 bytes c Check the number of runtime arguments If the number of arguments is not one, print out an error message to the console, and exit The message should state: Please specify a server name in the command line d In a try/catch block, verify that the named server computer exists by calling the GetHostByName method of the Dns class Catch any SocketException exceptions and write out to a console window the message “Cannot find server: ”, followed by the name of the server and the exception’s data Then exit the application e Connect to the named server using port 14 f Declare a variable of type Stream g In a try/catch block, get the stream and assign it to the variable declared in the preceding step Catch any InvalidOperationException exceptions and write out to a console window the message “Cannot connect to server ”, followed by the server’s name, and then exit the application h Read all of the bytes in the stream into the byte array that you created in step 6b, and store the number of bytes that are read in an integer i Convert the ASCII-encoded byte array into a string j Write out to a console window a message that states the number of bytes received and the current date and time string retrieved from the server Module 11: Internet Access 39 k Close the TcpClient object l Write out to a console window the following message: Press Enter to exit m Do a read from the console to wait for the Enter key and exit the application Build the client application ! Test the client and server applications Ensure that there are no server applications running on the computer using port 14, for example, other instances of the server application Tip You can display your computer’s current TCP/IP network connections by running the program netstat in a command prompt window The following example shows that port is in use by a process with PID 1504: C:\>netstat -o -n -a Active Connections Proto TCP Local Address 0.0.0.0:7 Foreign Address 0.0.0.0:0 State PID LISTENING 1504 … Run the server application in a Visual Studio NET Command Prompt window or in the Visual Studio NET debugger Run the client application in another Visual Studio NET Command Prompt window or in another Visual Studio NET debugger Do not specify any runtime arguments Note that the client application returns with the proper error message, as follows: Please specify a server name in the command line Run the client application as directed in step with a runtime argument that contains a nonexistent server name For example, assuming that there is no computer named foo on the network, enter the following text in a Visual Studio NET Command Prompt window: datetimeclient foo 40 Module 11: Internet Access Note that the client application returns with the proper error message, for example: Cannot find server: foo … Run the client application as directed in step with a runtime argument that contains the name of the computer on which the Datetimeserver application is running If the server application is running on your current computer, specify the local computer as follows: datetimeclient localhost Note that the client application outputs the number of bytes received and the current date and time string retrieved from the server Module 11: Internet Access 41 Review Topic Objective To reinforce module objectives by reviewing key points ! The WebRequest and WebResponse Model ! Application Protocols ! Handling Errors Security ! The review questions cover some of the key concepts taught in the module Internet Application Scenarios ! Lead-in ! Best Practices *****************************ILLEGAL FOR NON-TRAINER USE****************************** Name the four parts of the following URI: http://www.microsoft.com/default.htm?foo=bar Scheme identifier http Server identifier www.Microsoft.com Path identifier /default.htm Query String ?foo=bar Write the line of code that creates a WebRequest to the URI in question WebRequest req = WebRequest.Create ("http://www.microsoft.com/default.htm?foo=bar"); Write the line of code that gets a WebResponse from the WebRequest in question WebResponse resp = req.GetResponse(); Write the line of code that gets a Stream from the WebResponse in question Stream respstrm = resp.GetResponseStream(); 42 Module 11: Internet Access Name the type of Web-specific exceptions that are thrown by the GetResponse method WebException State how a WebRequest can be made to use the Secure Socket Layer (SSL) protocol URI begins with https Name at least three authentication methods that are supported by the NET Framework Basic Digest Negotiate NTLM Kerberos Module 11: Internet Access 43 Course Evaluation Topic Objective To direct students to a Web site to complete a course evaluation Lead-in Between now and the end of the course, you can go to the Web site listed on this page to complete a course evaluation *****************************ILLEGAL FOR NON-TRAINER USE****************************** Your evaluation of this course will help Microsoft understand the quality of your learning experience At a convenient time before the end of the course, please complete a course evaluation, which is available at http://www.metricsthatmatter.com/survey/ Microsoft will keep your evaluation strictly confidential and will use your responses to improve your future learning experience THIS PAGE INTENTIONALLY LEFT BLANK ... this module ! Complete the lab iv Module 11: Internet Access Module Strategy Use the following strategy to present this module: ! Internet Application Scenarios Briefly introduce examples of Internet. .. User Datagram Protocol (UDP), and Socket Internet protocols 2 Module 11: Internet Access Internet Application Scenarios Topic Objective To introduce Internet application scenarios that use the... data over the Internet by using a Web proxy, Secure Sockets Layer (SSL) encryption, Internet authentication, and the NET Framework’s code access permissions Module 11: Internet Access 29 Web