Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

C# ПІДРУЧНИКИ / c# / MS Press - Msdn Training Programming Net Framework With C#

.pdf
Скачиваний:
174
Добавлен:
12.02.2016
Размер:
16.87 Mб
Скачать

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.

7.Build the client application.

! Test the client and server applications

1.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 7 is in use by a process with PID 1504:

C:\>netstat -o -n -a

Active Connections

Proto

Local Address

Foreign Address

State

PID

TCP

0.0.0.0:7

0.0.0.0:0

LISTENING

1504 …

2.Run the server application in a Visual Studio .NET Command Prompt window or in the Visual Studio .NET debugger.

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

4.Note that the client application returns with the proper error message, as follows:

Please specify a server name in the command line

5.Run the client application as directed in step 3 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

40Module 11: Internet Access

6.Note that the client application returns with the proper error message, for example:

Cannot find server: foo

7.Run the client application as directed in step 3 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.

Lead-in

The review questions cover some of the key concepts taught in the module.

!Internet Application Scenarios

!The WebRequest and WebResponse Model

!Application Protocols

!Handling Errors

!Security

!Best Practices

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

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

2. Write the line of code that creates a WebRequest to the URI in question 1.

WebRequest req = WebRequest.Create ("http://www.microsoft.com/default.htm?foo=bar");

3.Write the line of code that gets a WebResponse from the WebRequest in question 2.

WebResponse resp = req.GetResponse();

4.Write the line of code that gets a Stream from the WebResponse in question 3.

Stream respstrm = resp.GetResponseStream();

42Module 11: Internet Access

5.Name the type of Web-specific exceptions that are thrown by the

GetResponse method.

WebException

6.State how a WebRequest can be made to use the Secure Socket Layer (SSL) protocol.

URI begins with https.

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

Module 12: Serialization

Contents

 

Overview

1

Serialization Scenarios

2

Serialization Attributes

4

Object Graph

5

Serialization Process

7

Serialization Example

9

Deserialization Example

10

Custom Serialization

12

Custom Serialization Example

14

Security Issues

17

Lab 12: Serialization

18

Review

27

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 12: Serialization

iii

 

 

 

Instructor Notes

Presentation:

30 Minutes

Lab:

45 Minutes

After completing this module, students will be able to:

Write an application that serializes and deserializes an object graph by using either a binary or Simple Object Access Protocol (SOAP) XML format.

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_12.ppt.

Preparation Tasks

To prepare for this module, you should:

!Read all of the materials for this module.

!Complete the lab.

iv

Module 12: Serialization

Module Strategy

Use the following strategy to present this module:

!Serialization Scenarios

Discuss briefly how serialization is used in scenarios such as persisting inmemory objects to disk and in remoting. Mention the Microsoft .NET Framework’s support for serialization and deserialization as an introduction to the rest of the module.

!Serialization Attributes

Explain how to mark a class with serialization attributes in C# by using the Serializable attribute. Also cover the NonSerialized attribute.

!Object Graph

Use the diagram on the Object Graph slide to discuss the object graph concept and the algorithm that is used to serialize or deserialize an object graph.

!Serialization Process

Introduce the classes that are used in the serialization process.

!Serialization Example

Discuss the code example on the Serialization Example slide in which default serialization is performed on a graph of objects, whose root is an ArrayList, and the serialized stream is written to a FileStream in binary format.

!Deserialization Example

Use the preceding serialization example to show how to create a clone of the graph by deserializing it.

!Custom Serialization

Discuss when to use custom serialization and the implementation details of using the ISerializable interface to perform custom serialization and deserialization.

!Custom Serialization Example

Show how to provide custom serialization for a class named

ISerializableExample.

!Security Issues

Because the serialization engine handles both the public and private state of the objects that are passed to it, emphasize that streams with private data should be treated carefully, and that some form of encryption should be used for sensitive data, before that data is transmitted over the wire or persisted to disk.

Соседние файлы в папке c#